Huawei Cloud RDS Instance List → Markdown Export
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), then render the instance name list as a Markdown table and write it
to a local .md file. The skill is aimed at RDS inventory / asset export,
daily operations patrol, handover reports and any "save the instance list as a
Markdown file" request.
Architecture:
agent → python3 scripts/list_rds_export_markdown.py → hcloud RDS ListInstances --cli-region=<region> --limit=N --offset=O
→ Huawei Cloud RDS OpenAPI (regional endpoint) → parsed JSON → Markdown table → local .md file
(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 validates the operation name and scans the arguments; mutating intents (create / delete / update / resize / restart / stop / restore ...) are rejected with an explicit message before any command runs. The.mdfile is generated on the local filesystem only — no RDS write happens and no user confirmation can make this skill issue a write. - 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. - Local sorting —
--sort-by name|createdorders the rows in memory after the full (paged) list has been fetched; the ListInstances API has no ordering parameter.namecompares case-insensitively with an id fallback,createdcompares parsed timestamps oldest-first (ISO-8601,Z/+0800offsets and space-separated values all accepted). Records whose sort key is missing are always placed last, unparseable timestamps fall back to text comparison, and the stable sort keeps ties in their original order. Omit--sort-byto keep the API order unchanged. - Empty result is not an error — an empty instance list (or a filter that
matches nothing) still produces a valid
.mdfile with the table header and an explicit "no instances" note, and exits0. - Atomic local file — the Markdown body is written to a temporary file and renamed into place, so an interrupted write never leaves a corrupt / partial file behind.
- Offline-testable — every code path (paging, filters, rendering, atomic write, error classification, guard, SDK fallback) is covered by unit tests that mock the hcloud subprocess.
Capability boundary: this skill lists instances only and exports them locally; it does not manage the instance lifecycle (create / delete / resize / restart / stop / restore backup / change password / read-replica management), and it does not export to Excel / PDF / CSV. Those require a separate skill.
Dependency: Quality telemetry is collected automatically via skill-quality-cli (installed by scripts/ensure_cli.sh if absent).
Differentiation from the plain RDS list skill
The repository keeps a terminal-oriented RDS instance-list skill and this Markdown-export skill side by side. They share the same read-only API but produce different artifacts, and they are not runtime dependencies of each other.
| Dimension | Plain RDS instance-list skill | This export skill |
|---|---|---|
| Deliverable | Terminal output (table / JSON / names-only) | A local Markdown file (default rds_instances.md) |
| Persistence | None — printed to stdout only | Atomic file write + automatic parent-directory creation |
| Purpose | Interactive inspection / pre-query an instance_id for downstream use |
Markdown report export for inventory, patrol, handover |
Per-service "query + export to a file" capabilities are an established repository convention and are kept as their own skill, separate from the plain list skill and named by the export format (a sibling compute service exports to Excel, a sibling storage service exports to Excel/PDF). This skill continues that convention for RDS with Markdown as the output format. Use the plain RDS instance-list skill to view instances in the terminal; use this skill when the instance list must be saved as a distributable / archivable Markdown document.
Prerequisites
- Python 3.8+ — the Markdown export uses only the Python standard library.
For the hcloud-absent fallback, run
python3 scripts/ensure_env.pyto installhuaweicloudsdkcore/huaweicloudsdkrdsautomatically. See references/cli-installation-guide.md. - KooCLI (
hcloud) installed — the primary path. See references/cli-installation-guide.md. Alternative:pip install huaweicloudsdkcore huaweicloudsdkrdsto enable the SDK fallback path. - KooCLI credentials configured out-of-band — the script never reads, echoes, or stores AK/SK itself; authentication is delegated to the active KooCLI profile (CLI path) or the whitelisted environment variables (SDK fallback). Never paste AK/SK into chat.
- IAM permission — read-only
rds:instance:list(or the system policy RDS ReadOnlyAccess); least-privilege policy in references/iam-policies.md. - Outbound HTTPS access to
rds.<region>.myhuaweicloud.com. - Write access to the local output directory (for the generated
.mdfile).
- skill-quality-cli — ensured by bash scripts/ensure_cli.sh (idempotent, skips if present)
- Upgrade: run skill-quality-cli upgrade manually (no auto-upgrade)
- Disable telemetry report: set SKILL_QUALITY_REPORT=0
Workflow
- (Optional) prepare the environment —
python3 scripts/ensure_env.pyinstallshuaweicloudsdkcore/huaweicloudsdkrdsif they are missing (needed only for the SDK fallback). - Confirm the target region (default
cn-north-4); every RDS call is region-scoped. Optionally pass--project_id. - Confirm KooCLI readiness (optional, read-only) — the credential check in Core Commands.
- Run the export script with the desired output path, optional filters and
an optional
--sort-byordering. - Read the result — the printed path is the generated Markdown report; open that file to see the instance-name table.
- Handle the empty / error cases per the Error Handling table below (an empty result still writes the file; credential / permission failures print an explicit hint and write nothing).
Core Commands
⚠️ Mandatory: every hcloud command in this skill MUST be wrapped with skill-quality-cli run --skill-name huawei-cloud-rds-export-markdown -- ** — bare hcloud calls are strictly forbidden.
# Default: query the region's RDS instances and write rds_instances.md in cwd
python3 scripts/list_rds_export_markdown.py --region cn-north-4
# Explicit output path (recommended) + echo the Markdown to stdout as well
python3 scripts/list_rds_export_markdown.py --region cn-north-4 \
--output /tmp/rds_instances_cn-north-4.md --stdout
# Name filter (server-side) and status filter (applied client-side)
python3 scripts/list_rds_export_markdown.py --name rds-demo --status ACTIVE \
--output /tmp/rds_active.md
# Sort by instance name (case-insensitive, id fallback) — applied client-side
python3 scripts/list_rds_export_markdown.py --region cn-north-4 \
--sort-by name --output /tmp/rds_sorted_by_name.md
# Sort by creation time, oldest first (client-side; missing/unparseable last)
python3 scripts/list_rds_export_markdown.py --region cn-north-4 \
--sort-by created --output /tmp/rds_sorted_by_created.md
# Filter first, then sort (status filtering runs before the ordering)
python3 scripts/list_rds_export_markdown.py --status ACTIVE --sort-by name \
--output /tmp/rds_active_sorted.md
# Project-scoped (mapped to the KooCLI global --cli-project-id)
python3 scripts/list_rds_export_markdown.py --project_id <project_id> \
--output /tmp/rds_project.md
# Read-only credential readiness check (wrapped)
skill-quality-cli run --skill-name huawei-cloud-rds-export-markdown -- hcloud configure list
Equivalent direct KooCLI command (the script wraps exactly this call, with
paging; wrap with skill-quality-cli run in production):
skill-quality-cli run --skill-name huawei-cloud-rds-export-markdown -- 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 |
--project_id / --project-id |
No | Project id; mapped to the KooCLI global --cli-project-id (the SDK path resolves it from credentials + region) |
<project_id> |
--output / -o |
No | Markdown output file path (default current dir rds_instances.md) |
/tmp/rds.md |
--name |
No | Filter by instance name (server-side ListInstances parameter) | rds-demo |
--status |
No | Filter by instance state — applied client-side (RDS ListInstances has no status API parameter; the full list is fetched, then filtered locally, case-insensitive) | ACTIVE, FAILED, BUILDING |
--sort-by |
No | Order the rows — applied client-side after the filters (the API has no ordering parameter): name = instance name ascending, case-insensitive, id fallback; created = creation time ascending (oldest first), missing/unparseable values last. Omitted → API order preserved |
name, created |
--page-size |
No | Page size for ListInstances (default 100) | 100 |
--operation |
No | hcloud RDS operation name; only ListInstances is allowed |
ListInstances |
--stdout |
No | Also print the rendered Markdown to stdout (the file is still written) | --stdout |
Markdown Output Format
The generated document has a title, a short metadata line, and a table with the
following columns (fields missing on an instance render as -):
| Column (header) | Source key | Notes |
|---|---|---|
| 实例名称 | name |
Instance name (falls back to ID) |
| 实例ID | id |
Instance ID |
| 状态 | status |
ACTIVE / FAILED / BUILDING ... |
| 引擎 | datastore.type |
Flattened engine type |
| 版本 | datastore.version |
Flattened engine version |
| 规格 | flavor_ref |
Flavor reference |
| 私网IP | private_ips |
Comma-joined; - when absent |
| 可用区 | nodes[0].availability_zone |
Primary node AZ |
| 创建时间 | created |
Creation timestamp |
An empty instance list produces the header + separator followed by a note line
_当前区域(<x>)无 RDS 实例。_ — the file is always created.
Write-Intent Guard
- The guard validates the
--operationvalue (only the read-onlyListInstancesis accepted) and scans the remaining arguments for mutating vocabulary (create,delete,update,modify,resize,restart,stop,start,shutdown,restore,destroy, and RDS operation names such asCreateInstance,DeleteInstance,ResizeFlavor). - Values of read-only flags (the local
--outputpath,--region,--project_id,--name,--status,--sort-by, ...) are excluded from the scan so a file path, a filter value or a sort option is never mistaken for an RDS operation.--sort-byis in that whitelist on purpose: its valuecreatedcontains the mutating keywordcreate, and both--sort-by createdand--sort-by=createdmust pass the guard. - Any hit raises
GuardError, prints[错误] 检测到写操作意图 ... 已被守卫拦截, and exits with code 1 before a single hcloud command is executed. No write operation can be constructed bybuild_command(); there is no code path that can issue a mutating RDS API call, so no user confirmation path exists — theCreate/Delete/Updateintents are refused outright.
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). - Project parameter —
--cli-project-id=<value>(global KooCLI option, emitted only when--project_idis supplied). - 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. There is likewise no ordering parameter —--sort-byis a script-side option only and is never sent to hcloud / the SDK. - REST path (official SDK
_http_info) —GET /v3/{project_id}/instances(huaweicloudsdkrdsv3_list_instances_http_info); project_id is resolved by KooCLI / the SDK from the credential profile.
Concrete raw KooCLI command (the script wraps exactly this call; wrap with
skill-quality-cli run --skill-name huawei-cloud-rds-export-markdown -- in
production):
| Command | Purpose |
|---|---|
hcloud RDS ListInstances --cli-region=cn-north-4 --limit=1 |
Read-only instance list used as the Markdown source |
Error Handling
| Scenario | Behavior |
|---|---|
| Empty instance list / no filter match | Exit 0; the .md file is still written (header + 无 RDS 实例 note) |
| Missing / invalid AK-SK | Exit 1, 缺少 AK/SK 凭证 hint to configure hcloud credentials out-of-band (never in chat); no file written |
| 403 / insufficient IAM permission | Exit 1, 无权限访问 RDS,请检查 IAM 权限 hint; no file written |
| hcloud not installed | Falls back to the SDK; if the SDK is unavailable too, exit 1 with a clear hint |
Bad --output path (permission / bad directory) |
Exit 1, Markdown 文件写出失败 hint; no partial file left |
KooCLI usage error ([USE_ERROR] ..., even with exit code 0) |
Exit 1, explicit hcloud 参数错误 hint pointing to hcloud RDS ListInstances --help |
Unknown --sort-by value |
Exit 1, --sort-by 仅支持 name 或 created(收到: xxx); fails before any API call, no file written |
| Network / API failure | Exit 1 with the hcloud stderr excerpt |
| Write intent detected | Exit 1, GuardError message, no command executed, no file written |
Exit codes: 0 success / empty list; 1 config, auth, guard, export, or API
error.
Edge Cases
| Scenario | Handling |
|---|---|
| Region has no instances | Header + empty-table note written, exit 0 |
| Many instances | Automatic offset paging (total_count aware, full-page fallback, max 100 pages) |
| Filter yields no instance | Empty message includes the active filters; the file is still written |
| Field missing on an instance | Rendered as - in the Markdown cell |
| ` | ` or newline inside a field |
--output points to a non-existing directory |
Directory is created automatically |
--output path contains a guard keyword (e.g. downloads/update-*.md) |
Path value is excluded from the guard (local path ≠ RDS operation) |
--status BUILDING |
Legitimate read filter — the status value is not sent to the server |
--sort-by omitted |
Original API order preserved (no reordering, output unchanged) |
--sort-by name with duplicate / mixed-case names |
Case-insensitive compare, stable sort keeps ties in the original relative order; records without name fall back to id |
--sort-by created with missing / unparseable timestamp |
Parse failure falls back to text comparison; a missing created is always placed last instead of aborting the export |
| hcloud absent, SDK installed | Transparent fallback to huaweicloudsdkrds list_instances, same Markdown output |
| User asks to create/delete/restart | Out of scope — blocked by the write-intent guard |
Testing
Offline unit tests with a mocked hcloud subprocess (no credentials, no network):
cd skills/database/rds/huawei-cloud-rds-export-markdown
python3 -m unittest discover -s tests -v
Coverage: write-intent guard (read passes / create / delete / mutating verbs /
normalized separators / operation whitelist / read-only value scrubbing including
--sort-by created and --flag=value forms), command construction
(--cli-region / limit / offset / name / --cli-project-id, no write flags / no
status / no ordering), JSON extraction and instance extraction, failure
classification (missing AK/SK, 403, generic, [USE_ERROR] with rc=0), offset
paging (total / full page / empty), client-side status filtering, local sorting
(--sort-by name case-insensitive + id fallback + missing last, --sort-by created mixed timestamp formats + text fallback + missing last + stable ties,
no-argument order preservation, unknown value), SDK fallback (env credentials /
missing credentials / unavailable), normalization, Markdown rendering (title /
header / rows / empty-result note / pipe & newline escaping), atomic file writing
(missing dirs / bad path), and all main() output modes (including the sorted
row order and the fail-fast exit 1 for an unknown --sort-by).
Reference Documents
| Document | Content |
|---|---|
| references/iam-policies.md | Least-privilege read-only IAM policy |
| references/cli-installation-guide.md | KooCLI + SDK installation, credential configuration and skill-quality-cli |
| 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 |
