Huawei Cloud DWS Cluster List
Overview
Query the DWS (Data Warehouse Service) cluster list of a tenant region through
KooCLI hcloud DWS ListClusters (official read-only
GET /v1.0/{project_id}/clusters, verified in the huaweicloudsdkdws v2 client
_list_clusters_http_info metadata — resource_path: "/v1.0/{project_id}/clusters").
The skill is aimed at DWS inventory inspection, daily operations patrol, and as a
pre-query step for other DWS skills that need a cluster_id.
Architecture:
agent → python3 scripts/list_dws.py → hcloud DWS ListClusters --cli-region=<region>
→ Huawei Cloud DWS OpenAPI (regional endpoint) → parsed JSON → table / --json / --names-only
(hcloud binary missing) → fallback: huaweicloudsdkdws v2 DwsClient.list_clusters
Key properties:
- Read-only by design — the only API ever invoked is
ListClusters(GET). A write-intent guard scans user arguments and validates the operation name; mutating intents (create / delete / update / resize / restart / stop / restore / upgrade / reboot ...) 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
huaweicloudsdkdwsv2 SDK (list_clusters). 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 ListClusters, with
endpoints/public_endpoints/public_ipflattened into readableendpoint/public_endpoint/publicIpcolumns. - Client-side filters & paging — the real ListClusters API has no name / id /
status / limit / offset parameters (only
enterprise_project_id); the script fetches the full list in a single call and applies those filters locally. - Offline-testable — every code path (filters, paging, error classification, guard, SDK fallback) is covered by unit tests that mock the hcloud subprocess.
Out of scope: every mutating DWS action (create / delete / resize / restart / stop / restore snapshot / reset password / upgrade / reboot). Those require a dedicated write-capable skill and explicit user confirmation.
Prerequisites
- KooCLI (
hcloud) installed — see references/cli-installation-guide.md. Alternative:pip install huaweicloudsdkdwsto 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 DWS list permission; 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 DWS 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_dws.py --region cn-north-4
# Raw JSON of every returned field
python3 scripts/list_dws.py --json
# Compact cluster-name list only
python3 scripts/list_dws.py --names-only
# Filter by cluster status (client-side exact, case-insensitive)
python3 scripts/list_dws.py --status AVAILABLE
# Filter by name (client-side substring) / exact ID
python3 scripts/list_dws.py --name dws-demo
python3 scripts/list_dws.py --cluster-id 6f8f7b0a-...
# Client-side pagination and the real enterprise-project API parameter
python3 scripts/list_dws.py --limit 20 --offset 0 --enterprise-project-id 0
# Combine filters
python3 scripts/list_dws.py --region cn-south-1 --status AVAILABLE \
--limit 10 --names-only
Equivalent direct KooCLI command (the script wraps exactly this call):
hcloud DWS ListClusters --cli-region=cn-north-4
hcloud DWS ListClusters --cli-region=cn-north-4 --enterprise_project_id=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 cluster array as JSON | — |
--names-only |
No | Output cluster names only | — |
--name |
No | Filter by cluster name — applied client-side (case-insensitive substring; the ListClusters API has no name parameter) | dws-demo |
--status |
No | Filter by cluster state — applied client-side (case-insensitive exact; API has no status parameter) | AVAILABLE, CREATING, FAILED |
--cluster-id |
No | Filter by exact cluster ID — applied client-side | 6f8f7b0a-... |
--limit |
No | Client-side pagination: max clusters returned (0 = unlimited, default 0) |
20 |
--offset |
No | Client-side pagination: skip the first N clusters (default 0) |
20 |
--enterprise-project-id |
No | Enterprise project ID — real ListClusters API parameter, forwarded to hcloud/SDK | 0 (default project), all_granted_eps |
--operation |
No | hcloud DWS operation name; only ListClusters is allowed |
ListClusters |
Output-mode precedence: --names-only → --json → table (default).
Filtering is applied before pagination: filter (name/status/id) → slice (offset/limit).
Write-Intent Guard
- The script scans all user arguments plus the
--operationvalue for mutating vocabulary (create,delete,update,resize,restart,stop,restore,upgrade,reboot,scale,terminate,destroy, and DWS operation names such asCreateCluster,DeleteCluster,ResizeCluster). - Any hit raises
GuardError, prints[错误] 检测到写操作意图 ... 已被守卫拦截, and exits with code 1 before a single hcloud command is executed. - Only
hcloud DWS ListClusters(GET) — or the SDKlist_clusterscall in the fallback path — is ever constructed bybuild_command(); there is no code path that can issue a mutating DWS API call.
KooCLI Command Format Standard
hcloud <Service> <Operation> --cli-region=<region> [--key=value ...]
- Service name — exact KooCLI title-case service name:
DWS. - Operation name — PascalCase:
ListClusters. - Region parameter —
--cli-region=<value>, e.g.--cli-region=cn-north-4(required for every concrete DWS call). - Simple parameter —
--key=value, e.g.--enterprise_project_id=0. There is no--name/--status/--id/--limit/--offsetparameter on the real DWS ListClusters API; those filters are applied client-side by the script, never forwarded to the CLI/API. - REST path (official SDK
_http_info) —GET /v1.0/{project_id}/clusters(huaweicloudsdkdwsv2_list_clusters_http_info); project_id is resolved by KooCLI from the credential profile.
Error Handling
| Scenario | Behavior |
|---|---|
| Empty cluster list | Exit 0, prints 当前区域(<x>)无 DWS 集群 (+ active filters) |
| 403 / insufficient IAM permission | Exit 1, 无权限访问 DWS,请检查 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 huaweicloudsdkdws |
| 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 DWS ListClusters --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 |
|---|---|
CREATING / FAILED clusters |
Reported with their state, not treated as failure |
--status / --name / --cluster-id filters |
Applied client-side after the full list is fetched (the server API has only enterprise_project_id) |
--limit / --offset |
Client-side slice applied after filtering (the server API has no paging) |
| Large cluster count | Single ListClusters call returns the whole list; local slicing keeps memory/output bounded by --limit |
| Extra response fields | Table columns are built from the union of returned fields — new fields appear automatically |
| Field missing on a cluster | Rendered as - in the table |
Nested endpoints / public_endpoints / public_ip |
Flattened into endpoint / public_endpoint / publicIp for the table |
| Non-JSON hcloud output | ApiError with the raw excerpt (first 200 chars) |
| hcloud absent, SDK installed | Transparent fallback to huaweicloudsdkdws list_clusters, 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 / upgrade / reboot / normalize variants / operation whitelist),
command construction (including "no unsupported filter ever sent to the
server"), JSON extraction, failure classification (missing AK/SK, 403, generic,
[USE_ERROR] with rc=0), client-side filters (name substring / status exact /
id exact / no-match / missing field), client-side pagination (limit / offset /
combined / overflow), SDK fallback (success and unavailable; request
construction matches the real ListClustersRequest signature),
rendering (table with version/node_type/endpoint/publicIp fields / names /
fallbacks), and all main() output modes including empty, filter, paging 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 |
