Advanced
Тема интерфейса

Step 4: View and Run Cloud Service Operation Commands

This section uses Windows as an example to describe how to use Cloud CLI. The methods for using the CLI in Linux and macOS are similar.

After the initialization is complete, you can query the cloud services supported by Cloud CLI and run operation commands. The following uses the Elastic Cloud Server (ECS) API for querying ECS details as an example to describe how to query and run a command.

  1. Query the operations of a cloud service.

    cloud <service> --help

    As shown below, Available Operations lists the operations supported by ECS.

    cloud ECS --help
    Cloud CLI Version 4.2.12
    Usage:
    cloud ECS <operation> --param1=value1 --param2=value2 ...
    Service:
    ECS
    Available Operations:
    AddServerGroupMember MigrateServer NovaShowServerAction
    AssociateServerVirtualIp NovaAssociateSecurityGroup NovaShowServerGroup
    AttachServerVolume NovaAttachInterface NovaShowServerInterface
    BatchAddServerNics NovaAttachVolume NovaShowServerMetadata
    ...
    Note
    • During command execution, your authentication information will be used for requests, and the invocation of some APIs will incur charges.
    • Alternatively, you can query the operations supported by a cloud service on API Explorer.
    • To query the cloud services supported by Cloud CLI, run the cloud --help command.

  2. Query the help information about an operation.

    cloud <service> <operation> --help

    Select NovaShowServer from the obtained ECS operation list to query the help information about the API. The API description, parameters, and parameter descriptions are displayed.

    cloud ECS NovaShowServer --help
    Cloud CLI Version 4.2.12
    Service:
    ECS
    Description:
    This API is used to query details about an ECS by ECS ID.
    Method:
    GET
    Params:
    --cli-region
    required string Region where the API can be called. If no region is specified in the command, cli-region in the current profile is used.
    --project_id
    required string path Specifies the project ID. If no project ID is specified in the command, either the parent project ID of the specified region in the authentication information or cli-project-id in the current profile is used.
    --server_id
    required string path Specifies the ECS ID.
    --OpenStack-API-Version
    optional string header API with a microversion.

  3. Run the command to call the API and obtain the execution result.

    cloud <service> <operation> [--param1=paramValue1 --param2=paramValue2 ...]

    After you enter cli-region (region), project_id (project ID), and server_id (ECS ID) and press Enter, the ECS information is returned.

    cloud ECS NovaShowServer --cli-region="ru-moscow-1" --project_id="0dd8cb****************19b5a84546" --server_id="4f06****-****-****-****-****04dd856a"
    {
    "server": {
    "tenant_id": "0dd8cb****************19b5a84546",
    "metadata": {},
    "addresses": {
    "c865****-****-****-****-****efe7e8d8": [
    {
    "OS-EXT-IPS-MAC:mac_addr": "fa:**:**:**:**:**",
    "OS-EXT-IPS:type": "fixed",
    "addr": "192.***.*.**",
    "version": 4
    }
    ]
    },
    "OS-EXT-STS:task_state": null,
    "OS-DCF:diskConfig": "AUTO",
    "OS-EXT-AZ:availability_zone": "ru-moscow-1a",
    "links": [
    {
    "rel": "self",
    "href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/v2.1/0dd8cb****************19b5a84546/servers/4f06****-****-****-****-****04dd856a"
    },
    {
    "rel": "bookmark",
    "href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/0dd8cb****************19b5a84546/servers/4f06****-****-****-****-****04dd856a"
    }
    ],
    "OS-EXT-STS:power_state": 4,
    "id": "4f06****-****-****-****-****04dd856a",
    "os-extended-volumes:volumes_attached": [
    {
    "id": "aed9****-****-****-****-****0e3219cf"
    }
    ],
    "OS-EXT-SRV-ATTR:host": "51f41ce46********************************38b69b7aa4ea2a8",
    "image": {
    "links": [
    {
    "rel": "bookmark",
    "href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/0dd8cb****************19b5a84546/images/67f4****-****-****-****-****38539e09"
    }
    ],
    "id": "67f4****-****-****-****-****38539e09"
    },
    "OS-SRV-USG:terminated_at": null,
    "accessIPv4": "",
    "accessIPv6": "",
    "created": "2022-05-10T12:56:36Z",
    "hostId": "51f41ce46********************************38b69b7aa4ea2a8",
    "OS-EXT-SRV-ATTR:hypervisor_hostname": "cf199aabae********************************bed586126e6f57",
    "flavor": {
    "links": [
    {
    "rel": "bookmark",
    "href": "https://ecs.ru-moscow-1.hc.sbercloud.ru/0dd8cb****************19b5a84546/flavors/s6.medium.2"
    }
    ],
    "id": "s6.medium.2"
    },
    "key_name": null,
    "security_groups": [
    {
    "name": "Sys-**********"
    }
    ],
    "OS-EXT-STS:vm_state": "stopped",
    "user_id": "b4d561****************346deaf79e",
    "OS-EXT-SRV-ATTR:instance_name": "instance-*******",
    "name": "ecs-****",
    "OS-SRV-USG:launched_at": "2022-05-10T12:56:53.000000",
    "updated": "2022-05-13T08:05:17Z",
    "status": "SHUTOFF"
    }
    }
    Note
    • When using Cloud CLI to call APIs, you can obtain example CLI commands on API Explorer.
    • Cloud CLI automatically obtains the account ID and project ID of an IAM user based on the user authentication information during API calling. The user does not need to specify cli-region in the command if it has already been specified in the configuration information.
    • If a parameter value in the command is incorrect, an error message is displayed as follows:
      cloud ECS ShowServer --project_id="0dd8cb****************19b5a84546" --cli-region="ru-moscow-1" --server_id="abc"
      {
      "error": {
      "message": "Instance[abc] could not be found.",
      "code": "Ecs.0114"
      }
      }
      For details, go to the API Error Center at 'https://console.hc.sbercloud.ru/apiexplorer/#/errorcenter?keyword=Ecs.0114&product=ECS'.