Overview
This skill is used to query information about Huawei Cloud Elastic Cloud Servers (ECS), including:
- Query instance list: List the basic information of all ECS instances
- Query instance details: Get the detailed configuration information of a single ECS instance
- Query instance status: View the running status of an ECS instance
Supports two authentication methods (AK/SK signature authentication and Token authentication), two output formats (table and JSON), and multi-region queries.
Prerequisites
1. Install Python dependencies
pip install requests pyyaml
2. Obtain authentication credentials
Method 1: AK/SK authentication (recommended)
- Log in to the Huawei Cloud console → username in the upper right corner → "My Credentials" → "Access Keys" → Add Access Key
- Save the AK (Access Key ID) and SK (Secret Access Key)
- You also need to obtain the Project ID: view it on the "My Credentials" page
Method 2: Token authentication
- Requires the username and password of the Huawei Cloud account
- Requires the account's Domain ID (tenant ID, viewable on the "My Credentials" page)
- Requires the Project ID
3. Configuration file
Create a configuration file ~/.huawei-ecs/config.yaml(or specify the path via the --config parameter):
# 认证方式:aksk 或 token
auth_method: aksk
# AK/SK 认证配置
ak: "your-access-key-id"
sk: "your-secret-access-key"
project_id: "your-project-id"
# Token 认证配置(当 auth_method 为 token 时使用)
# username: "your-username"
# password: "your-password"
# domain_id: "your-domain-id"
# 默认区域
region: "cn-north-4"
# 输出格式:table 或 json
output_format: "table"
Workflow
When a user requests ECS information query, execute according to the following process:
- Identify the query type: Determine whether the user needs the instance list (list), instance details (show), or instance status (status)
- Confirm the authentication configuration: Check whether
~/.huawei-ecs/config.yamlexists; if missing, prompt the user to complete the configuration first (refer to the "Prerequisites" section) - Execute the query: Run the corresponding command according to the query type (refer to the "Core Commands" section)
- List →
list-servers(can add--status/--namefilter) - Details →
show-server - Status →
server-status
- List →
- Format the output: Table output by default; when the user requests JSON, use
--output json - Handle errors: When an API request fails, based on the error message prompt the user to check the network, region, or permissions (refer to "Notes" and
references/troubleshooting.md)
Core Commands
hcloud CLI equivalent commands (recommended)
This skill's script implements queries through direct connection to Huawei Cloud APIs. If hcloud CLI (KooCLI) is already installed in the environment and hcloud configurehas been completed, you can use the following equivalent commands for quick queries:
# 查询实例列表
hcloud ECS ListServersDetails --cli-region=cn-north-4 --limit=25
# 查询单个实例详情
hcloud ECS ShowServer --cli-region=cn-north-4 --server_id=<server_id>
# 查询实例状态(结合 --cli-query 过滤)
hcloud ECS ListServersDetails --cli-region=cn-north-4 --status=ACTIVE
For CLI installation and authentication methods, refer to references/cli-installation-guide.md。
Script Commands
Query instance list
python scripts/ecs_query.py list-servers --config config.yaml
Optional parameters:
--region: Specify the region (such as cn-north-4, cn-east-3, ap-southeast-1)--output: Output format (table or json)--limit: Return quantity limit (default 25)--offset: Page number offset (default 1)--status: Filter by status (ACTIVE, SHUTOFF, BUILD, ERROR, etc.)--name: Filter by name--flavor: Filter by flavor ID
Query instance details
python scripts/ecs_query.py show-server --server-id <server_id> --config config.yaml
How to get server_id: If you do not know the instance ID, first run
python scripts/ecs_query.py list-servers --config config.yaml(orhcloud ECS ListServersDetails --cli-region=<region>), and copy the ID column of the target instance from the results.
Query instance status
python scripts/ecs_query.py server-status --server-id <server_id> --config config.yaml
How to get server_id: Same as above, first use
list-serversto get the instance ID.
Output description
Table format
The instance list is displayed in table form, containing the following columns:
| Column name | Description |
|---|---|
| ID | Server ID |
| Name | Server name |
| Status | Running status |
| Flavor | Flavor type |
| vCPU | Number of virtual CPU cores |
| RAM(MB) | Memory size |
| Private IP | Private IP address |
| Public IP | Elastic public IP |
| Created | Creation time |
| AZ | Availability zone |
Status description
| Status value | Meaning |
|---|---|
| ACTIVE | Running |
| SHUTOFF | Shut down |
| BUILD | Creating |
| ERROR | Fault |
| REBOOT | Restarting |
| HARD_REBOOT | Forced restarting |
| MIGRATING | Migrating |
| RESIZE | Changing flavor |
| VERIFY_RESIZE | Verifying flavor change |
API reference
For detailed API interface descriptions, please refer to references/api-reference.md。
Troubleshooting
- Missing configuration file: Create it according to the "Prerequisites" section
~/.huawei-ecs/config.yaml - Authentication failed: Check whether the AK/SK or Token configuration is correct, and whether the account has ECS read-only permission
- Connection failed: Check whether the network can access
ecs.{region}.myhuaweicloud.com - For more troubleshooting guidance, see
references/troubleshooting.md
Notes
- Security reminder: The configuration file contains sensitive credential information. Please keep it properly and do not commit it to a version control system
- Network requirements: It needs to be able to access Huawei Cloud API endpoints (
ecs.{region}.myhuaweicloud.com) - Permission requirements: The account/IAM user used needs to have ECS read-only permission (ECS ReadOnlyAccess). For detailed policies, see
references/iam-policies.md - Region support: Huawei Cloud has multiple regions. Common regions include:
- cn-north-4 (North China-Beijing 4)
- cn-north-1 (North China-Beijing 1)
- cn-east-3 (East China-Shanghai 1)
- cn-south-1 (South China-Guangzhou)
- ap-southeast-1 (China-Hong Kong)
- ap-southeast-2 (Asia Pacific-Singapore)
- AK/SK signature: Uses the SDK-HMAC-SHA256 signature algorithm, consistent with Huawei Cloud official signature specifications