更新时间:2026-09-07 GMT+08:00

如何使用CLI

华为云命令行工具服务(Koo Command Line Interface,KooCLI,原名HCloud CLI)是为发布在API Explorer上的云服务API提供的命令行管理工具。您可以通过此工具调用API Explorer中VPC开放的API,管理和使用您的VPC资源。关于KooCLI的详细信息,请参见什么是KooCLI

安装KooCLI

在使用KooCLI前,您需要先安装KooCLI。KooCLI支持Windows、Linux和macOS三种操作系统,请根据您机器所使用的操作系统,安装对应版本的工具。

配置KooCLI初始化

使用KooCLI调用API时,需要获取调用者的身份信息用于认证鉴权。通过配置KooCLI初始化,可以把永久AK/SK信息存储在配置文件中,避免在调用API时频繁输入这些固定信息。

如果您不希望通过配置文件传入认证信息,而是直接在命令中传入认证相关参数,可跳过此步骤,具体操作可参见无配置方式使用KooCLI

此处以Windows系统为例介绍如何配置KooCLI的初始化,Linux和MacOS系统的操作类似。在配置初始化前,您需要提前获取AK/SK信息,具体操作请参见新增访问密钥

  1. 打开命令行窗口。
  2. 执行以下命令进行初始化配置。
    hcloud configure init
  3. 根据界面提示输入各参数值。
    Access Key ID [required]:      //必填,输入AK 
    Secret Access Key [required]:      //必填,输入SK,输入内容时系统会匿名化处理 
    Secret Access Key (again):      //必填,再次输入SK,输入内容时系统会匿名化处理 
    Region:      //选填,输入Region

    完成后,界面提示“初始化配置成功”。

生成和执行CLI命令

KooCLI支持两种命令生成方式:

  • 通过API Explorer快速生成并获取调用API的CLI命令。推荐通过API Explorer获取CLI命令,更方便快捷。
  • 通过CLI命令查询API的操作命令和相关参数信息,然后手动拼接调用API的CLI命令,具体操作可参见查看与执行云服务操作命令

此处以创建安全组API为例,介绍如何从API Explorer生成CLI命令,然后执行CLI命令调用API。

  1. API Explorer的VPC服务页面,选择要生成CLI命令的API。
  2. 在中间的参数配置界面中,填写调用API所需的参数。
  3. 在右侧界面选择“CLI示例”页签,可查看生成的CLI命令。
    创建安全组API的CLI命令示例如下。
    hcloud VPC CreateSecurityGroup/v3 --cli-region="cn-north-7" --security_group.name="test4koocli"
  4. 复制生成的CLI命令,并粘贴到命令行窗口中执行。
    创建安全组API的CLI命令执行结果示例如下。
    {
      "security_group": {
        "name": "test4koocli",
        "id": "f5a9ccb8-94c3-49cf-a4ed-5046e0e13327",
        "project_id": "e69f635ad1d54d55923027a09d727e38",
        "description": "",
        "enterprise_project_id": "0",
        "security_group_rules": [
          {
            "id": "4840b593-9cbb-4d1a-a179-1a90fca2bb29",
            "project_id": "e69f635ad1d54d55923027a09d727e38",
            "security_group_id": "f5a9ccb8-94c3-49cf-a4ed-5046e0e13327",
            "remote_group_id": null,
            "direction": "egress",
            "protocol": null,
            "description": "",
            "created_at": "2026-08-31T07:30:13Z",
            "updated_at": "2026-08-31T07:30:13Z",
            "ethertype": "IPv6",
            "remote_ip_prefix": null,
            "multiport": null,
            "remote_address_group_id": null,
            "action": "allow",
            "priority": 100,
            "enabled": true
          },
          {
            "id": "3f5dabff-0f12-40d3-b74f-e3b4371df2c6",
            "project_id": "e69f635ad1d54d55923027a09d727e38",
            "security_group_id": "f5a9ccb8-94c3-49cf-a4ed-5046e0e13327",
            "remote_group_id": null,
            "direction": "egress",
            "protocol": null,
            "description": "",
            "created_at": "2026-08-31T07:30:13Z",
            "updated_at": "2026-08-31T07:30:13Z",
            "ethertype": "IPv4",
            "remote_ip_prefix": null,
            "multiport": null,
            "remote_address_group_id": null,
            "action": "allow",
            "priority": 100,
            "enabled": true
          },
          {
            "id": "62e7a5e4-ca15-4e01-ae73-d0328423c905",
            "project_id": "e69f635ad1d54d55923027a09d727e38",
            "security_group_id": "f5a9ccb8-94c3-49cf-a4ed-5046e0e13327",
            "remote_group_id": "f5a9ccb8-94c3-49cf-a4ed-5046e0e13327",
            "direction": "ingress",
            "protocol": null,
            "description": "",
            "created_at": "2026-08-31T07:30:13Z",
            "updated_at": "2026-08-31T07:30:13Z",
            "ethertype": "IPv6",
            "remote_ip_prefix": null,
            "multiport": null,
            "remote_address_group_id": null,
            "action": "allow",
            "priority": 100,
            "enabled": true
          },
          {
            "id": "03acdea3-36b2-46d7-8748-bc7debea777e",
            "project_id": "e69f635ad1d54d55923027a09d727e38",
            "security_group_id": "f5a9ccb8-94c3-49cf-a4ed-5046e0e13327",
            "remote_group_id": "f5a9ccb8-94c3-49cf-a4ed-5046e0e13327",
            "direction": "ingress",
            "protocol": null,
            "description": "",
            "created_at": "2026-08-31T07:30:13Z",
            "updated_at": "2026-08-31T07:30:13Z",
            "ethertype": "IPv4",
            "remote_ip_prefix": null,
            "multiport": null,
            "remote_address_group_id": null,
            "action": "allow",
            "priority": 100,
            "enabled": true
          }
        ],
        "created_at": "2026-08-31T07:30:13Z",
        "updated_at": "2026-08-31T07:30:13Z",
        "tags": []
      },
      "request_id": "90e2ee0bd865f156e823adf323f1e34a"
    }