Huawei Cloud RDS Instance List
Overview
Query the RDS instance list of a tenant region through KooCLI
hcloud RDS ListInstances (official read-only GET /v3/{project_id}/instances,
verified in the huaweicloudsdkrds v3 client _list_instances_http_info
metadata). The skill is aimed at RDS inventory inspection, daily operations
patrol, and as a pre-query step for other RDS skills that need an instance_id.
Architecture:
agent → python3 scripts/list_rds.py → hcloud RDS ListInstances --cli-region=<region>
→ Huawei Cloud RDS OpenAPI (regional endpoint) → parsed JSON → table / --json / --names-only
(hcloud binary missing) → fallback: huaweicloudsdkrds v3 RdsClient.list_instances
Key properties:
- Read-only by design — the only API ever invoked is
ListInstances(GET). A write-intent guard scans user arguments and validates the operation name; mutating intents (create / delete / update / resize / restart / stop / restore ...) are rejected with an explicit message before any command runs. - CLI first, SDK fallback — KooCLI is the primary execution path; when the
hcloud binary is absent, the script falls back to the official
huaweicloudsdkrdsv3 SDK (list_instances). Credentials are always read by the CLI profile / SDK environment — never handled by the script. - Full-field table output — the default table renders the union of all
fields returned by ListInstances, with
datastoreflattened into engine/engineVersion andprivate_ipsjoined for readability. - Offline-testable — every code path (paging, filters, error classification, guard, SDK fallback) is covered by unit tests that mock the hcloud subprocess.
Out of scope: every mutating RDS action (create / delete / resize / restart / stop / restore backup / change password / read-replica management). Those require a dedicated write-capable skill and explicit user confirmation.
Prerequisites
- KooCLI (
hcloud) installed — see references/cli-installation-guide.md. Alternative:pip install huaweicloudsdkrdsto enable the SDK fallback path. - Active credential profile — configure credentials out-of-band
(
hcloud configurein your terminal, or credential environment variables). Never paste AK/SK into chat; the script never reads, echoes, or stores secrets itself — authentication is delegated entirely to the hcloud profile / SDK environment. - IAM permission — read-only
rds:instance:list; least-privilege policy in references/iam-policies.md. - Python 3.8+ (standard library only — argparse / json / subprocess).
- Outbound HTTPS access to
*.myhuaweicloud.com.
Workflow
- Confirm the target region (default
cn-north-4); every RDS call is region-scoped. - Confirm hcloud readiness (optional, read-only):
hcloud configure list. - Run the list script with the desired output mode and filters.
- Read the result — table for humans,
--jsonfor downstream tooling,--names-onlyfor a compact inventory. - Handle the empty / error cases per the Edge Cases table below (the script prints an explicit hint for empty region, 403, and missing AK/SK).
Core Commands
# Full-field table (default)
python3 scripts/list_rds.py --region cn-north-4
# Raw JSON of every returned field
python3 scripts/list_rds.py --json
# Compact instance-name list only
python3 scripts/list_rds.py --names-only
# Filter by instance status (client-side: full list fetched, then filtered
# locally — the RDS ListInstances API has no status query parameter)
python3 scripts/list_rds.py --status ACTIVE
# Filter by engine / name
python3 scripts/list_rds.py --datastore-type MySQL --name rds-demo
# Combine filters
python3 scripts/list_rds.py --region cn-south-1 --status ACTIVE --names-only
Equivalent direct KooCLI command (the script wraps exactly this call, with paging):
hcloud RDS ListInstances --cli-region=cn-north-4 --limit=100 --offset=0
Parameter Confirmation
| Parameter | Required | Description | Example |
|---|---|---|---|
--region / -r |
No | Huawei Cloud region (default cn-north-4) |
cn-south-1 |
--json |
No | Output the raw instance array as JSON | — |
--names-only |
No | Output instance names only | — |
--status |
No | Filter by instance state — applied client-side (RDS ListInstances has no status API parameter; full list fetched, then filtered locally, case-insensitive) | ACTIVE, FAILED, BUILDING |
--name |
No | Filter by instance name | rds-demo-01 |
--datastore-type |
No | Filter by engine | MySQL, PostgreSQL, SQLServer |
--instance-id |
No | Filter by exact instance ID | rds-0001 |
--page-size |
No | Page size for ListInstances (default 100) | 100 |
--operation |
No | hcloud RDS operation name; only ListInstances is allowed |
ListInstances |
Output-mode precedence: --names-only → --json → table (default).
Write-Intent Guard
- The script scans all user arguments plus the
--operationvalue for mutating vocabulary (create,delete,update,resize,restart,stop,restore, and RDS operation names such asCreateInstance,DeleteInstance,ResizeFlavor). - Any hit raises
GuardError, prints[错误] 检测到写操作意图 ... 已被守卫拦截, and exits with code 1 before a single hcloud command is executed. - Only
hcloud RDS ListInstances(GET) — or the SDKlist_instancescall in the fallback path — is ever constructed bybuild_command(); there is no code path that can issue a mutating RDS API call.
KooCLI Command Format Standard
hcloud <Service> <Operation> --cli-region=<region> [--key=value ...]
- Service name — exact KooCLI title-case service name:
RDS. - Operation name — PascalCase:
ListInstances. - Region parameter —
--cli-region=<value>, e.g.--cli-region=cn-north-4(required for every concrete RDS call). - Simple parameter —
--key=value, e.g.--limit=100,--offset=20,--name=rds-01,--datastore_type=MySQL,--id=rds-01. There is no--statusparameter on the real RDS ListInstances API (verified viahcloud RDS ListInstances --help); status filtering is done client-side by the script, never forwarded to the CLI/API. - REST path (official SDK
_http_info) —GET /v3/{project_id}/instances(huaweicloudsdkrdsv3_list_instances_http_info); project_id is resolved by KooCLI from the credential profile.
Error Handling
| Scenario | Behavior |
|---|---|
| Empty instance list | Exit 0, prints 当前区域(<x>)无 RDS 实例 (+ active filters) |
| 403 / insufficient IAM permission | Exit 1, 无权限访问 RDS,请检查 IAM 权限 hint |
| Missing / invalid AK-SK | Exit 1, explicit hint to configure hcloud credentials out-of-band (never in chat) |
| hcloud not installed | Exit 1 after SDK fallback also unavailable, hint to install KooCLI or pip install huaweicloudsdkrds |
| Network / API failure | Exit 1 with the hcloud stderr excerpt |
KooCLI usage error ([USE_ERROR] ..., even with exit code 0) |
Exit 1, explicit hcloud 参数错误 hint pointing to hcloud RDS ListInstances --help |
| Write intent detected | Exit 1, GuardError message, no command executed |
Exit codes: 0 success / empty region; 1 config, auth, guard, or API error.
Edge Cases
| Scenario | Handling |
|---|---|
BUILDING / FAILED instances |
Reported with their state, not treated as failure |
--status filter |
Applied client-side after the full paged list is fetched (case-insensitive); the server API has no status parameter |
| Large instance count | Automatic offset paging (total_count aware, full-page fallback, max 100 pages) |
| Extra response fields | Table columns are built from the union of returned fields — new fields appear automatically |
| Field missing on an instance | Rendered as - in the table |
Nested datastore / nodes / private_ips |
Flattened into engine / engineVersion / availability_zone / privateIps for the table |
| Non-JSON hcloud output | ApiError with the raw excerpt (first 200 chars) |
| hcloud absent, SDK installed | Transparent fallback to huaweicloudsdkrds list_instances, same output modes |
| User asks to create/delete/resize | Out of scope — blocked by the write-intent guard; a write-capable skill with explicit user confirmation is required |
Testing
Offline unit tests with a mocked hcloud subprocess (no credentials, no network):
python3 -m unittest discover -s tests -v
Coverage: write-intent guard (read passes / create / delete / resize / restart
/ stop / restore / normalize variants / operation whitelist), command
construction (including "status never sent to the server"), JSON extraction,
failure classification (missing AK/SK, 403, generic, [USE_ERROR] with rc=0),
client-side status filtering (exact / case-insensitive / no-match / missing
field), paging (total / full-page / empty), SDK fallback (success and
unavailable; request construction matches the real ListInstancesRequest
signature — status= must raise TypeError), rendering (table with
engine/flavor/private IP fields / names / fallbacks), and all main() output
modes including empty, filter, and error paths.
Reference Documents
| Document | Content |
|---|---|
| references/iam-policies.md | Least-privilege read-only IAM policy |
| references/cli-installation-guide.md | KooCLI installation and credential configuration |
| references/verification-method.md | How the skill and its tests were verified |
| references/dataflow-diagram.md | Mermaid data flow diagram |
| references/acceptance-criteria.md | Acceptance criteria checklist |
