Huawei Cloud GaussDB Count Skill
Overview
This skill queries the total number of Huawei Cloud GaussDB instances in a region and outputs the count. It supports both GaussDB product families:
- GaussDB for openGauss — primary/standby (Ha) and distributed (Enterprise)
instances, queried via the
GaussDBforopenGaussservice. - GaussDB (MySQL-compatible) — instances queried via the
GaussDBservice.
The count is taken from the authoritative total_count field returned by the
list API, so the result is exact regardless of page size — no pagination sum is
needed for the count itself.
Architecture:
Agent → hcloud CLI (primary) → Huawei Cloud GaussDB API
↘ Python SDK (fallback) ↗
Applicable Scenarios:
- Daily inspection: how many GaussDB instances exist in a region
- Database inventory and cost review
- Capacity planning and pre-migration verification
Prerequisites
- hcloud CLI installed and authenticated — See
references/cli-installation-guide.md - Python 3.8+ with
huaweicloudsdkgaussdbforopengaussandhuaweicloudsdkgaussdbpackages (SDK fallback) - Huawei Cloud AK/SK configured via environment variables or the hcloud CLI profile
- IAM permissions — read-only access to GaussDB instances — See
references/iam-policies.md
Workflow
- Identify query scope — Decide which region to query
- Select execution mode — Use the hcloud CLI by default; fall back to the Python SDK if the CLI is unavailable
- Execute the query — Run the count commands and capture
total_countfrom each response - Present results — Output the GaussDB instance count to the user
Core Commands
Count GaussDB for openGauss Instances
| Purpose | Command |
|---|---|
| Count all GaussDB for openGauss instances | hcloud GaussDBforopenGauss ListInstances --cli-region={region} --limit=100 |
Count GaussDB (MySQL-compatible) Instances
| Purpose | Command |
|---|---|
| Count all GaussDB (MySQL) instances | hcloud GaussDB ListGaussMySqlInstances --cli-region={region} --limit=100 |
Count-Only Lookup (jq)
To return just the numeric count:
hcloud GaussDBforopenGauss ListInstances --cli-region={region} --limit=100 | jq -r '.total_count'
hcloud GaussDB ListGaussMySqlInstances --cli-region={region} --limit=100 | jq -r '.total_count'
SDK Fallback Examples
When the CLI is unavailable, use the Python SDK:
import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkgaussdbforopengauss.v3.region.gaussdbforopengauss_region import GaussDBforopenGaussRegion
from huaweicloudsdkgaussdbforopengauss.v3 import GaussDBforopenGaussClient, ListInstancesRequest
credentials = BasicCredentials().with_ak(os.getenv("HUAWEI_ACCESS_KEY")) \
.with_sk(os.getenv("HUAWEI_SECRET_KEY"))
client = GaussDBforopenGaussClient.new_builder() \
.with_credentials(credentials) \
.with_region(GaussDBforopenGaussRegion.value_of("{region}")) \
.build()
response = client.list_instances(ListInstancesRequest(limit=100))
print(response.total_count)
import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
from huaweicloudsdkgaussdb.v3 import GaussDBClient, ListGaussMySqlInstancesRequest
credentials = BasicCredentials().with_ak(os.getenv("HUAWEI_ACCESS_KEY")) \
.with_sk(os.getenv("HUAWEI_SECRET_KEY"))
client = GaussDBClient.new_builder() \
.with_credentials(credentials) \
.with_region(GaussDBRegion.value_of("{region}")) \
.build()
response = client.list_gauss_my_sql_instances(ListGaussMySqlInstancesRequest(limit=100))
print(response.total_count)
A ready-to-run helper script is provided in scripts/count_gaussdb_instances.py covering both product families. The script catches
ClientRequestException/SdkException and prints a concise, actionable error message (credential / region / IAM-permission hint) then exits
non-zero — it never dumps a raw traceback.
Parameter Confirmation
| Parameter | Required | Description | Example |
|---|---|---|---|
{region} |
Yes | Huawei Cloud region | cn-north-4 |
{limit} |
No | Max records per page (1-100, default 100); does not affect total_count |
100 |
Reference Documents
KooCLI Command Format Standard
hcloud <Service> <Operation> --cli-region=<region> [--key=value ...]
| Feature | Description | Example |
|---|---|---|
| Service name | GaussDBforopenGauss, GaussDB |
hcloud GaussDBforopenGauss ListInstances --cli-region={region} |
| Operation name | PascalCase | ListInstances, ListGaussMySqlInstances |
| Region parameter | --cli-region=<value> |
--cli-region=cn-north-4 |
| Simple parameter | --key=value |
--limit=100 |
