Help Center/ Koo Command Line Interface/ Getting Started/ Step 4: View and Run Cloud Service Operation Commands
Updated on 2023-02-27 GMT+08:00

Step 4: View and Run Cloud Service Operation Commands

This section uses Windows as an example to describe how to use KooCLI. 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 KooCLI 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.

    hcloud <service> --help

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

    hcloud ECS --help
    
    KooCLI(Koo Command Line Interface) Version 3.2.8 Copyright(C) 2023-2023 www.huaweicloud.com
    
    Usage:
      hcloud ECS <operation> --param1=value1 --param2=value2 ...
    
    Service:
      ECS
    
    Available Operations:
      AddServerGroupMember             MigrateServer                    NovaShowServerAction
      AssociateServerVirtualIp         NovaAssociateSecurityGroup       NovaShowServerGroup
      AttachServerVolume               NovaAttachInterface              NovaShowServerInterface
      BatchAddServerNics               NovaAttachVolume                 NovaShowServerMetadata
      ...
    • Alternatively, you can query the operations supported by a cloud service on API Explorer.
    • To query the cloud services supported by KooCLI, run the hcloud --help command.

    By default, KooCLI uses the offline mode, and automatically downloads the offline metadata package when executing commands for the first time. Once downloaded, the package will not be automatically updated. To invoke newly launched services in the offline mode, run the hcloud meta download command to update the offline metadata package, or run the hcloud configure set --cli-offline=false command to switch to the online mode.

  2. Query the help information about an operation.

    hcloud <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.

    hcloud ECS NovaShowServer --help
    
    KooCLI(Koo Command Line Interface) Version 3.2.8 Copyright(C) 2023-2023 www.huaweicloud.com
    
    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.

    hcloud <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.

    hcloud ECS NovaShowServer --cli-region="eu-west-101" --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": "",
      "links": [
       {
        "rel": "self",
        "href": "https://ecs.eu-west-101.myhuaweicloud.eu/v2.1/0dd8cb****************19b5a84546/servers/4f06****-****-****-****-****04dd856a"
       },
       {
        "rel": "bookmark",
        "href": "https://ecs.eu-west-101.myhuaweicloud.eu/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.eu-west-101.myhuaweicloud.eu/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.eu-west-101.myhuaweicloud.eu/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"
     }
    }
    • When using KooCLI to call APIs, you can obtain example CLI commands on API Explorer.
    • KooCLI 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:
      hcloud ECS ShowServer --project_id="0dd8cb****************19b5a84546" --cli-region="eu-west-101" --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.eu.huaweicloud.com/apiexplorer/#/errorcenter?keyword=Ecs.0114&product=ECS'.