
Huawei Cloud Storage Query
- 106 installs
- 19 repo stars
- Updated July 31, 2026
- huaweicloud/huaweicloud-skills
Query Huawei Cloud storage resources (EVS/OBS/SFS/CBR): disks, snapshots, buckets, file systems, and backup vaults/policies, read-only.
About
Read-only queries of Huawei Cloud storage resources across EVS cloud disks, OBS buckets, SFS Turbo file systems, and CBR backups via bundled Python scripts. A developer uses it to inspect disk info, buckets, file-system status, and backup/policy details.
- Covers EVS, OBS, SFS Turbo, and CBR resources
- Read-only; runs through bundled Python scripts
Huawei Cloud Storage Query by the numbers
- 106 all-time installs (skills.sh)
- +14 installs in the week ending Aug 2, 2026 (Skillselion tracking)
- Ranked #554 of 1,042 Cloud & Infrastructure skills by installs in the Skillselion catalog
- Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/huaweicloud/huaweicloud-skills --skill huawei-cloud-storage-queryAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 106 |
|---|---|
| repo stars | ★ 19 |
| Last updated | July 31, 2026 |
| Repository | huaweicloud/huaweicloud-skills ↗ |
What it does
Query Huawei Cloud storage resources (EVS/OBS/SFS/CBR): disks, snapshots, buckets, file systems, and backup vaults/policies, read-only.
Files
Huawei Cloud Resource Query
⚠️ Execution Method (Must Read): This skill executes queries via local Python scripts. Using hcloud, openstack, or other CLI tools or direct API calls is prohibited.
>
- Query scripts are located under the skill directoryscripts/<service_category>/(e.g.,scripts/as/list_scaling_groups.py)
- All scripts and environment check scripts are inside the skill package, must be executed using `skill action=exec`, do not run them directly in the shell
- For specific script paths and parameters, refer to references/<service>/guide.md- Do not attempt hcloud, openstack, curl IAM, or other CLI/API methods; this skill does not depend on those tools
- All paths are relative to the skill directory, which is the directory where this SKILL.md resides
Overview
This skill is a standalone read-only query skill that uses local Python scripts to call the Huawei Cloud Python SDK to query Huawei Cloud resources, available specifications, and existing resource information.
This skill is applicable to the following scenarios:
1. Query available cloud resource specifications in a given region 2. Query available images for a given OS type 3. Query disk types and existing disk information 4. Query existing resources and their key attributes 5. Query resources not created via Terraform or other IaC tools 6. Prepare real parameters for automated configuration, resource verification, or environment inventory 7. Obtain reusable information such as resource ID, name, specification, image, network, disk, etc.
This skill does NOT handle the following:
1. Creating resources 2. Modifying resources 3. Deleting resources 4. Guessing or fabricating information that has not been queried
---
Capabilities
This skill provides query capabilities through categorized scripts in the scripts directory, and usage instructions through categorized guides in the references directory.
The capabilities provided by this skill include:
1. Query resource lists 2. Query individual resource details 3. Query available specifications, images, disk types, and other selection information 4. Query key identifiers and dependency relationships of existing resources
---
Usage Principles
Important: Script paths executed within this skill are all relative to the skill directory, which is the directory where this SKILL.md resides
1. This skill only performs queries, no write operations 2. Prefer explicitly specified region, project, AZ, resource name, resource ID, etc. from the user 3. Query results must be based on actual API responses, not inferred from experience 4. Returned results should prioritize key fields for subsequent reuse 5. When the result set is large, narrow the scope first using conditions like region, name, id, status, tag, etc. 6. If no corresponding script or guide exists for the current resource type, clearly state that it is unsupported; do not return unreliable results 7. If the user has not provided necessary scope information and no default values exist in the environment, confirm before executing the query 8. Execute directly according to guide.md; do not read the script contents in the scripts directory 9. Cache output when it is large 10. Before executing each script, always run -h first to view usage 11. Do not fabricate script names; execute according to the script names in guide.md. If a script name is not found in guide.md, it means it is not supported
---
Prerequisites
Before use, you must run the environment check script to complete environment validation and dependency installation in one step:
- Linux / macOS:
skill action=exec: bash skill://scripts/check_env.sh - Windows:
skill action=exec: powershell -ExecutionPolicy Bypass -File skill://scripts/check_env.ps1
Windows Note: Do not use && to chain commands (PowerShell 5.x does not support it); use semicolons if you need to change directories firstThe script will check in sequence: Python >= 3.6 → install dependencies → validate SDK → validate credentials → validate service availability. If the environment check fails, fix the issues before proceeding with other scripts.
Environment Variables:
| Variable | Required | Description |
|---|---|---|
| HW_ACCESS_KEY | Yes | Huawei Cloud AK |
| HW_SECRET_KEY | Yes | Huawei Cloud SK |
| HW_REGION_NAME | No | Default cn-north-4 |
| HW_PROJECT_ID | No | Project ID (automatically obtained via IAM API when not set) |
| HW_SECURITY_TOKEN | No | Required for temporary AK/SK |
Do not output the values of the above environment variables. For additional parameters required by other resource scripts (availability zone, enterprise project, etc.), refer to the corresponding guide.md.
---
Execution Flow
When this skill is invoked, the following steps must be executed without waiting for the user to prompt again:
Step 1: Environment Preparation
Run the environment check script to ensure dependencies are installed and credentials are configured:
- Linux / macOS:
skill action=exec: bash skill://scripts/check_env.sh - Windows:
skill action=exec: powershell -ExecutionPolicy Bypass -File skill://scripts/check_env.ps1
If the environment check fails, fix as prompted and re-run until it passes.
Step 2: Identify and Execute Query Script
1. Based on the user's query intent, read references/<service>/guide.md to determine the script path and parameters to execute 2. First run -h to view script usage:
- Linux / macOS:
skill action=exec: skill://.venv/bin/python3 skill://scripts/<service>/<script>.py -h - Windows:
skill action=exec: skill://.venv/Scripts/python3.exe skill://scripts/<service>/<script>.py -h
3. Assemble parameters based on user requirements and execute the script:
- Linux / macOS:
skill action=exec: skill://.venv/bin/python3 skill://scripts/<service>/<script>.py <parameters> - Windows:
skill action=exec: skill://.venv/Scripts/python3.exe skill://scripts/<service>/<script>.py <parameters>
4. Format the results and return to the user
Important:
- All scripts and environment check scripts are inside the skill package, must be executed using `skill action=exec`, do not run them directly in the shell
- The venv is automatically created by the check_env script; on Linux/macOS Python is located at
.venv/bin/python3, on Windows at.venv/Scripts/python3.exe - Do not execute scripts directly with
python3 - Do not read the script source code in the scripts directory; just follow the instructions in guide.md
- Cache results when output is large
- The
--project_idparameter is optional; when not provided, it is automatically obtained via IAM API based on region
---
Directory Structure
The directory conventions are as follows (all paths are relative to the skill directory):
1. scripts/<resource_category>/ contains the corresponding Python query scripts. No need to read script contents; execute scripts according to the usage instructions in guide.md 2. references/<resource_category>/guide.md contains the corresponding resource usage guide 3. Each script is responsible for a single, clear query action 4. Each resource category maintains at least one guide.md to describe script capabilities, parameters, and usage
---
Parameter Confirmation
Before executing a query script, confirm the following parameters:
| Parameter | Required | Description |
|---|---|---|
| region | Yes | Huawei Cloud region, e.g., cn-north-4 |
| --project_id | No | Project ID, automatically obtained when not provided |
| --availability_zone | No | Availability zone, required for some resource queries |
For other script-specific parameters, refer to references/<service>/guide.md.
---
Output Format
Query results are output in JSON format, containing the following common fields:
total: Total number of matched resourcesitems: Resource list, each resource contains key fields such as id, name, status, etc.- Specific fields vary by resource type; see individual guide.md for details
---
Verification Method
1. Run the environment check script to confirm dependencies and credentials are available 2. Use the -h parameter to view script usage and confirm parameters are correct 3. Execute queries against known resources and compare with console data to verify result accuracy 4. Check that the returned total count is reasonable
---
Best Practices
1. Narrow the query scope first (specify region, availability zone, etc.) to avoid returning too much data 2. Use --help to view the complete list of parameters supported by the script 3. Cache large query results locally to avoid repeated requests 4. When multiple resource information is needed, query in dependency order (e.g., query VPC first, then subnets) 5. When script execution fails, check environment variables and network connectivity first
---
Reference Documentation
- Service query script usage guides:
references/<service>/guide.md
---
Notes
1. This skill only provides read-only query capabilities; no write operations are performed 2. Do not output the values of HW_ACCESS_KEY, HW_SECRET_KEY, and other environment variables 3. All scripts must be executed via skill action=exec; do not run them directly in the shell 4. Do not guess script names; strictly execute according to the names in guide.md 5. The environment check script must be run before querying 6. When using temporary AK/SK, HW_SECURITY_TOKEN must be set
CBR Python Script Usage Guide
---
Vaults
list_vault.py — List Vaults
Purpose: List CBR vaults, supports filtering by name, object type, protection type, status, policy ID, enterprise project, etc. Output fields: id, name, status, object type, protection type, capacity (GB), used (MB), creation time, availability zone. Required: --project_id; Optional: --region, --limit, --name, --offset, --cloud_type, --protect_type, --object_type, --enterprise_project_id, --id, --policy_id, --status, --resource_ids. Usage: python scripts/cbr/list_vault.py -h
---
show_vault.py — Show Specified Vault Details
Purpose: Show CBR vault details, including basic info (id, name, description, project ID, availability zone, auto-bind, auto-expand, SMN notification, threshold, etc.), billing info (billing mode, cloud type, consistency level, object type, protection type, capacity, used, allocated, status, spec code, etc.), binding rules, bound resource list (id, name, type, protection status, size, backup size, backup count, excluded/included volumes), tag list. Required: --project_id, --vault_id; Optional: --region. Usage: python scripts/cbr/show_vault.py -h
---
list_external_vault.py — List Vaults in Other Regions
Purpose: List CBR external vaults in other regions, supports filtering by protection type, region ID, resource type, cloud type, vault ID. Output fields: id, name, status, object type, protection type, capacity (GB), used (MB), creation time, availability zone. Required: --project_id, --external_project_id; Optional: --region, --limit, --offset, --protect_type, --region_id, --objcet_type, --cloud_type, --vault_id. Usage: python scripts/cbr/list_external_vault.py -h
---
show_summary.py — Vault Capacity Summary
Purpose: Show CBR vault capacity summary, including total capacity (GB) and used capacity (GB). Required: --project_id; Optional: --region. Usage: python scripts/cbr/show_summary.py -h
---
Checkpoints
show_checkpoint.py — Show Backup Checkpoint Details
Purpose: Show specified backup checkpoint details, including checkpoint id, status, project ID, creation time, extended info (name, description, retention duration), associated vault info (id, name, resource list with protection status/resource size/backup size/backup count, skipped resource list with reason). Required: --project_id, --checkpoint_id; Optional: --region. Usage: python scripts/cbr/show_checkpoint.py -h
---
Backups
list_backups.py — List All Backups
Purpose: List CBR backups, supports filtering by checkpoint ID, backup type, name, resource ID/name/type/availability zone, status, vault ID, enterprise project, time range, etc. Output fields: id, name, status, resource type, resource name, resource size (GB), vault ID, backup type, creation time, incremental. Required: --project_id; Optional: --region, --checkpoint_id, --dec, --end_time, --image_type, --limit, --marker, --name, --offset, --resource_az, --resource_id, --resource_name, --resource_type, --sort, --start_time, --status, --vault_id, --enterprise_project_id, --own_type, --member_status, --parent_id, --used_percent, --show_replication, --incremental. Usage: python scripts/cbr/list_backups.py -h
---
show_backup.py — Show Specified Backup Details
Purpose: Show CBR backup details, including id, name, description, status, resource ID, resource name, resource type, resource size, vault ID, backup type, incremental, creation time, expiration time, protection time, checkpoint ID, enterprise project ID, provider ID. Required: --project_id, --backup_id; Optional: --region. Usage: python scripts/cbr/show_backup.py -h
---
show_metadata.py — Show Backup Metadata
Purpose: Show CBR backup metadata, including backup ID, backups, flavor, floatingips, interface, ports, server, volumes. Required: --project_id, --backup_id; Optional: --region. Usage: python scripts/cbr/show_metadata.py -h
---
Policies
list_policies.py — List Policies
Purpose: List CBR policies, supports filtering by policy type (backup/replication) and vault ID. Output fields: id, name, enabled, policy type, associated vault count. Required: --project_id; Optional: --region, --operation_type, --vault_id. Usage: python scripts/cbr/list_policies.py -h
---
show_policy.py — Show Specified Policy Details
Purpose: Show CBR policy details, including id, name, enabled, operation type (backup/replication), policy type. Required: --project_id, --policy_id; Optional: --region. Usage: python scripts/cbr/show_policy.py -h
---
Organization Policies
list_organization_policies.py — List Organization Policies
Purpose: List CBR organization policies. Output fields: id, name, policy type, enabled, status. Required: --project_id, --operation_type (backup/replication); Optional: --region, --limit, --offset. Usage: python scripts/cbr/list_organization_policies.py -h
---
list_organization_policy_detail.py — List Organization Policy Deployment Status
Purpose: List CBR organization policy deployment status. Output fields: policy ID, domain ID, project ID, status. Required: --project_id, --organization_policy_id; Optional: --region. Usage: python scripts/cbr/list_organization_policy_detail.py -h
---
show_organization_policy.py — Show Specified Organization Policy Details
Purpose: Show CBR organization policy details, including id, name, description, operation type, domain ID, domain name, enabled, status, scope. Required: --project_id, --organization_policy_id; Optional: --region. Usage: python scripts/cbr/show_organization_policy.py -h
---
Tasks
list_op_logs.py — List Tasks
Purpose: List CBR tasks, supports filtering by task type, status, time range, vault ID/name, resource ID/name, enterprise project, etc. Output fields: id, task type, status, backup provider ID, vault ID, vault name, creation time. Required: --project_id; Optional: --region, --end_time, --limit, --offset, --operation_type, --provider_id, --resource_id, --resource_name, --start_time, --status, --vault_id, --vault_name, --enterprise_project_id. Usage: python scripts/cbr/list_op_logs.py -h
---
show_op_log.py — Show Single Task Details
Purpose: Show CBR task details, including id, task type, status, provider ID, vault ID, vault name, project ID, policy ID, checkpoint ID, creation time, start time, end time, update time. Required: --project_id, --operation_log_id; Optional: --region. Usage: python scripts/cbr/show_op_log.py -h
---
Protectables
list_protectable.py — List Protectable Resources
Purpose: List CBR protectable resources, supports filtering by name, status, resource ID, cloud server ID. Output fields: id, name, type, size (GB), status. Required: --project_id, --protectable_type (e.g., OS::Nova::Server, OS::Cinder::Volume, OS::Sfs::Turbo, OS::Workspace::DesktopV2); Optional: --region, --limit, --marker, --name, --offset, --status, --id, --server_id. Usage: python scripts/cbr/list_protectable.py -h
---
show_protectable.py — Show Specified Protectable Resource Details
Purpose: Show CBR specified protectable resource details, including id, name, type, size, status. Required: --project_id, --protectable_type, --instance_id; Optional: --region. Usage: python scripts/cbr/show_protectable.py -h
---
check_agent.py — Check Agent Status
Purpose: Check CBR resource client agent status, supports batch query. Output fields: resource ID, installed, version, status code, message. Required: --project_id, --resource_ids (comma-separated), --resource_types (comma-separated, one-to-one with resource_ids); Optional: --region, --resource_names. Usage: python scripts/cbr/check_agent.py -h
---
show_replication_capabilities.py — Show Replication Capabilities
Purpose: Show CBR cross-region replication capabilities, output includes each region name and its supported replication target regions. Required: --project_id; Optional: --region. Usage: python scripts/cbr/show_replication_capabilities.py -h
---
File Backup Agents
list_agent.py — List Agents
Purpose: List CBR file backup agents, supports filtering by status and agent ID. Output fields: agent_id, version, type, hostname, host IP, OS, status, last activation time. Required: --project_id; Optional: --region, --limit, --offset, --status, --agent_id. Usage: python scripts/cbr/list_agent.py -h
---
show_agent.py — Show Specified Agent Details
Purpose: Show CBR file backup agent details, including agent_id, version, type, hostname, host nickname, host IP, OS, status, last activation time, creation time, update time, backup path list (path ID, directory path, status, exclude paths). Required: --project_id, --agent_id; Optional: --region. Usage: python scripts/cbr/show_agent.py -h
---
Feature Query
list_features.py — List Supported Features
Purpose: List CBR service supported features, returns complete feature information. Required: --project_id; Optional: --region, --limit, --offset. Usage: python scripts/cbr/list_features.py -h
---
show_feature.py — Show Specified Feature Details
Purpose: Show CBR specified feature details, returns complete feature information. Required: --project_id, --feature_key; Optional: --region, --limit, --offset. Usage: python scripts/cbr/show_feature.py -h
---
Backup Sharing
show_members_detail.py — List Backup Members
Purpose: List CBR backup sharing members, supports filtering by target project ID, image ID, status, vault ID, etc. Output fields: member ID, status, backup ID, target project ID, vault ID, creation time. Required: --project_id, --backup_id; Optional: --region, --dest_project_id, --image_id, --status, --vault_id, --limit, --marker, --offset, --sort. Usage: python scripts/cbr/show_members_detail.py -h
---
show_member_detail.py — Show Backup Member Details
Purpose: Show CBR backup sharing member details, including id, status, backup ID, image ID, target project ID, vault ID, creation time, update time. Required: --project_id, --backup_id, --member_id; Optional: --region. Usage: python scripts/cbr/show_member_detail.py -h
---
Projects and Domains
list_projects.py — List Tenant Projects
Purpose: List CBR tenant projects. Output fields: project ID, name, domain ID, enabled. Optional: --project_id, --region. Usage: python scripts/cbr/list_projects.py -h
---
show_domain.py — Show Tenant Information
Purpose: Show CBR domain information, including project name, project ID, domain ID, domain name. Required: --source_project_id; Optional: --project_id, --region. Usage: python scripts/cbr/show_domain.py -h
---
list_domain_projects.py — List Domain Projects
Purpose: List CBR projects under a domain. Output fields: project ID, project name. Required: --domain_name; Optional: --project_id, --region. Usage: python scripts/cbr/list_domain_projects.py -h
---
show_migrate_status.py — Show Migration Status
Purpose: Show CBR migration status, including overall status and per-project migration status list. Optional: --project_id, --region, --all_regions. Usage: python scripts/cbr/show_migrate_status.py -h
---
Metering
show_storage_usage.py — Show Storage Usage Statistics
Purpose: Show CBR storage usage statistics, including resource count and per-resource resource ID, resource name, resource type, backup count, backup size (GB), multi-AZ backup size. Required: --project_id; Optional: --region, --limit, --offset, --resource_id, --resource_type. Usage: python scripts/cbr/show_storage_usage.py -h
---
Tags
show_vault_tag.py — Show Vault Resource Tags
Purpose: Show CBR tags for a specified vault, including user tags (key/value) and system tags (key/value). Required: --project_id, --vault_id; Optional: --region. Usage: python scripts/cbr/show_vault_tag.py -h
---
show_vault_project_tag.py — Show Vault Project Tags
Purpose: Show CBR tags for all vaults in a project. Required: --project_id; Optional: --region. Usage: python scripts/cbr/show_vault_project_tag.py -h
---
show_vault_resource_instances.py — Query Vault Resource Instances by Tag
Purpose: Query CBR vault resource instances by tag filtering, supports AND/OR/exclude tag conditions, field matching, filtering by cloud type/object type, supports filter and count operations. Output: total count, resource ID, resource name, vault info (id, name, status, object type, protection type, capacity, used). Required: --project_id; Optional: --region, --action, --limit, --offset, --tags, --tags_any, --not_tags, --not_tags_any, --without_any_tag, --cloud_type, --object_type, --matches, --render_offset. Usage: python scripts/cbr/show_vault_resource_instances.py -h
EVS Python Script Usage Guide
---
cinder_list_availability_zones.py — List Availability Zones
Purpose: List availability zones. Usage: python scripts/evs/cinder_list_availability_zones.py -h
---
cinder_list_quotas.py — List Quotas
Purpose: List quotas. Usage: python scripts/evs/cinder_list_quotas.py -h
---
cinder_list_volume_transfers.py — List Volume Transfer Records
Purpose: List volume transfer records. Usage: python scripts/evs/cinder_list_volume_transfers.py -h
---
cinder_list_volume_types.py — List Volume Types
Purpose: List volume types. Usage: python scripts/evs/cinder_list_volume_types.py -h
---
cinder_show_volume_transfer.py — Show Volume Transfer Record Details
Purpose: Show volume transfer record details. Usage: python scripts/evs/cinder_show_volume_transfer.py -h
---
list_snapshots.py — List Volume Snapshots
Purpose: List volume snapshots. Usage: python scripts/evs/list_snapshots.py -h
---
list_versions.py — List EVS API Version Information
Purpose: List EVS API version information. Usage: python scripts/evs/list_versions.py -h
---
list_volume_tags.py — List Tags for All Volumes
Purpose: List tags for all volumes. Usage: python scripts/evs/list_volume_tags.py -h
---
list_volumes.py — List Volumes
Purpose: List volumes. Usage: python scripts/evs/list_volumes.py -h
---
list_volumes_in_recycle.py — List Volumes in Recycle Bin
Purpose: List volumes in the recycle bin. Usage: python scripts/evs/list_volumes_in_recycle.py -h
---
show_recycle_policy.py — Show Recycle Bin Policy
Purpose: Show recycle bin policy. Usage: python scripts/evs/show_recycle_policy.py -h
---
show_snapshot.py — Show Volume Snapshot Details
Purpose: Show volume snapshot details. Usage: python scripts/evs/show_snapshot.py -h
---
show_version.py — Show Specified EVS API Version Information
Purpose: Show specified EVS API version information. Usage: python scripts/evs/show_version.py -h
---
show_volume.py — Show Volume Details
Purpose: Show volume details. Usage: python scripts/evs/show_volume.py -h
---
show_volume_in_recycle.py — Show Volume Details in Recycle Bin
Purpose: Show volume details in the recycle bin. Usage: python scripts/evs/show_volume_in_recycle.py -h
---
show_volume_tags.py — Show Tags for a Specified Volume
Purpose: Show tags for a specified volume. Usage: python scripts/evs/show_volume_tags.py -h
OBS Python Script Usage Guide
---
get_bucket_acl.py — Get Bucket ACL
Purpose: Get bucket ACL. Usage: python scripts/obs/get_bucket_acl.py -h
---
get_bucket_customdomain.py — Get Bucket Custom Domain
Purpose: Get bucket custom domain. Usage: python scripts/obs/get_bucket_customdomain.py -h
---
get_bucket_metadata.py — Get Bucket Metadata
Purpose: Get bucket metadata. Usage: python scripts/obs/get_bucket_metadata.py -h
---
get_bucket_notification.py — Get Bucket Notification Configuration
Purpose: Get bucket notification configuration. Usage: python scripts/obs/get_bucket_notification.py -h
---
get_bucket_object_lock.py — Get Bucket Object Lock Configuration
Purpose: Get bucket object lock configuration. Usage: python scripts/obs/get_bucket_object_lock.py -h
---
get_bucket_policy_public_status.py — Get Bucket Policy Public Status
Purpose: Get bucket policy public status. Usage: python scripts/obs/get_bucket_policy_public_status.py -h
---
get_bucket_public_access_block.py — Get Bucket Public Access Block Configuration
Purpose: Get bucket public access block configuration. Usage: python scripts/obs/get_bucket_public_access_block.py -h
---
get_bucket_public_status.py — Get Bucket Public Status
Purpose: Get bucket public status. Usage: python scripts/obs/get_bucket_public_status.py -h
---
get_dis_policy.py — Get Bucket DIS Notification Policy
Purpose: Get bucket DIS notification policy. Usage: python scripts/obs/get_dis_policy.py -h
---
get_object.py — Get Object Content
Purpose: Get object content. Usage: python scripts/obs/get_object.py -h
---
get_object_tagging.py — Get Object Tags
Purpose: Get object tags. Usage: python scripts/obs/get_object_tagging.py -h
---
head_object.py — Get Object Metadata
Purpose: Get object metadata. Usage: python scripts/obs/head_object.py -h
---
list_buckets.py — List Buckets
Purpose: List buckets. Usage: python scripts/obs/list_buckets.py -h
---
list_objects.py — List Objects in Bucket
Purpose: List objects in a bucket. Usage: python scripts/obs/list_objects.py -h
SFS Python Script Usage Guide
---
list_backend_targets.py — List Backend Storage Targets
Purpose: List backend storage targets. Usage: python scripts/sfs/list_backend_targets.py -h
---
list_fs_tasks.py — List File System Tasks
Purpose: List file system tasks. Usage: python scripts/sfs/list_fs_tasks.py -h
---
list_hpc_cache_tasks.py — List HPC Cache Tasks
Purpose: List HPC cache tasks. Usage: python scripts/sfs/list_hpc_cache_tasks.py -h
---
list_perm_rules.py — List File System Permission Rules
Purpose: List file system permission rules. Usage: python scripts/sfs/list_perm_rules.py -h
---
list_share_types.py — List File System Types
Purpose: List file system types. Usage: python scripts/sfs/list_share_types.py -h
---
list_shared_tags.py — List Tags Supported by SFS Turbo File Systems
Purpose: List tags supported by SFS Turbo file systems. Usage: python scripts/sfs/list_shared_tags.py -h
---
list_shares.py — List SFS Turbo File Systems
Purpose: List SFS Turbo file systems. Usage: python scripts/sfs/list_shares.py -h
---
list_shares_by_tag.py — List SFS Turbo File Systems by Tag
Purpose: List SFS Turbo file systems by tag. Usage: python scripts/sfs/list_shares_by_tag.py -h
---
show_active_directory_domain.py — Show File System AD Domain Information
Purpose: Show file system AD domain information. Usage: python scripts/sfs/show_active_directory_domain.py -h
---
show_backend_target_info.py — Show Backend Storage Target Details
Purpose: Show backend storage target details. Usage: python scripts/sfs/show_backend_target_info.py -h
---
show_client_ip_info.py — Show File System Client IP Information
Purpose: Show file system client IP information. Usage: python scripts/sfs/show_client_ip_info.py -h
---
show_fs_dir.py — Show File System Directory Details
Purpose: Show file system directory details. Usage: python scripts/sfs/show_fs_dir.py -h
---
show_fs_dir_quota.py — Show File System Directory Quota
Purpose: Show file system directory quota. Usage: python scripts/sfs/show_fs_dir_quota.py -h
---
show_fs_dir_usage.py — Show File System Directory Usage
Purpose: Show file system directory usage. Usage: python scripts/sfs/show_fs_dir_usage.py -h
---
show_fs_task.py — Show File System Task Details
Purpose: Show file system task details. Usage: python scripts/sfs/show_fs_task.py -h
---
show_hpc_cache_task.py — Show HPC Cache Task Details
Purpose: Show HPC cache task details. Usage: python scripts/sfs/show_hpc_cache_task.py -h
---
show_job_detail.py — Show Job Details
Purpose: Show job details. Usage: python scripts/sfs/show_job_detail.py -h
---
show_ldap_config.py — Show File System LDAP Configuration
Purpose: Show file system LDAP configuration. Usage: python scripts/sfs/show_ldap_config.py -h
---
show_perm_rule.py — Show File System Permission Rule Details
Purpose: Show file system permission rule details. Usage: python scripts/sfs/show_perm_rule.py -h
---
show_quota.py — Show File System Quota
Purpose: Show file system quota. Usage: python scripts/sfs/show_quota.py -h
---
show_share.py — Show SFS Turbo File System Details
Purpose: Show SFS Turbo file system details. Usage: python scripts/sfs/show_share.py -h
---
show_shared_tags.py — Show Tags for a Specified SFS Turbo File System
Purpose: Show tags for a specified SFS Turbo file system. Usage: python scripts/sfs/show_shared_tags.py -h
huaweicloudsdkcore>=3.1.0
huaweicloudsdkiam>=3.1.0
huaweicloudsdkevs>=3.1.0
huaweicloudsdksfsturbo>=3.1.0
huaweicloudsdkobs>=3.1.0
huaweicloudsdkcbr>=3.1.0import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model.check_agent_request import CheckAgentRequest
from huaweicloudsdkcbr.v1.model.protectable_agent_req import ProtectableAgentReq
from huaweicloudsdkcbr.v1.model.protectable_agent_status_resource import ProtectableAgentStatusResource
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 客户端状态")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--resource_ids", type=str, required=True, help="资源ID列表,多个以英文逗号分隔")
parser.add_argument("--resource_names", type=str, help="资源名称列表,多个以英文逗号分隔,与resource_ids一一对应")
parser.add_argument("--resource_types", type=str, required=True, help="资源类型列表,多个以英文逗号分隔,与resource_ids一一对应,取值: OS::Nova::Server, OS::Cinder::Volume, OS::Sfs::Turbo, OS::Workspace::DesktopV2")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
resource_ids = [rid.strip() for rid in args.resource_ids.split(',') if rid.strip()]
resource_names = [n.strip() for n in args.resource_names.split(',') if n.strip()] if args.resource_names else []
resource_types = [t.strip() for t in args.resource_types.split(',') if t.strip()]
if len(resource_types) != len(resource_ids):
print(f"resource_types 数量({len(resource_types)})与 resource_ids 数量({len(resource_ids)})不一致,必须一一对应")
exit(1)
if resource_names and len(resource_names) != len(resource_ids):
print(f"resource_names 数量({len(resource_names)})与 resource_ids 数量({len(resource_ids)})不一致,必须一一对应")
exit(1)
req_body = ProtectableAgentReq()
agents = []
for i, rid in enumerate(resource_ids):
agent_res = ProtectableAgentStatusResource(resource_id=rid, resource_type=resource_types[i])
if i < len(resource_names):
agent_res.resource_name = resource_names[i]
agents.append(agent_res)
req_body.agent_status = agents
request = CheckAgentRequest()
request.body = req_body
response = client.check_agent(request)
agent_status = getattr(response, 'agent_status', []) or []
if not agent_status:
print(f"没有找到客户端状态信息 (区域: {Region})")
exit(0)
output = f"resource_id\tinstalled\tversion\tcode\tmessage\n"
for agent in agent_status:
resource_id = getattr(agent, 'resource_id', '')
installed = getattr(agent, 'installed', '')
version = getattr(agent, 'version', '')
code = getattr(agent, 'code', '')
message = getattr(agent, 'message', '')
output += f"{resource_id}\t{installed}\t{version}\t{code}\t{message}\n"
print(output)
except Exception as e:
print(f"cbr.check_agent 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListAgentRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 客户端列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--limit", type=str, help="每页显示条目数,正整数")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
parser.add_argument("--status", type=str, help="状态: normal/abnormal/uninstall")
parser.add_argument("--agent_id", type=str, help="客户端ID,多个以英文逗号分隔")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(agents):
total = len(agents)
if Offset >= total:
print(f"查询结果为空\n\n客户端列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"agent_id\tagent_version\tagent_type\thost_name\thost_ip\thost_os\tstatus\tlast_active_time\n"
for i in range(Offset, min(total, Offset + 50)):
agent = agents[i]
agent_id = getattr(agent, 'agent_id', '')
agent_version = getattr(agent, 'agent_version', '')
agent_type = getattr(agent, 'agent_type', '')
host_name = getattr(agent, 'host_name', '')
host_ip = getattr(agent, 'host_ip', '')
host_os = getattr(agent, 'host_os', '')
status = getattr(agent, 'status', '')
last_active_time = getattr(agent, 'last_active_time', '')
output += f"{agent_id}\t{agent_version}\t{agent_type}\t{host_name}\t{host_ip}\t{host_os}\t{status}\t{last_active_time}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n客户端列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListAgentRequest()
if args.limit:
request.limit = args.limit
if args.status:
request.status = args.status
if args.agent_id:
request.agent_id = args.agent_id
response = client.list_agent(request)
agents = getattr(response, 'agents', []) or []
count = getattr(response, 'count', 0)
if not agents:
print(f"没有找到客户端 (区域: {Region})")
exit(0)
render(agents)
except Exception as e:
print(f"cbr.list_agent 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListBackupsRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 备份列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--checkpoint_id", type=str, help="还原点ID")
parser.add_argument("--dec", type=bool, help="是否专属")
parser.add_argument("--end_time", type=str, help="结束时间")
parser.add_argument("--image_type", type=str, help="备份类型")
parser.add_argument("--limit", type=int, default=1000, help="返回结果个数限制,默认1000")
parser.add_argument("--marker", type=str, help="分页标记")
parser.add_argument("--name", type=str, help="备份名称")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
parser.add_argument("--resource_az", type=str, help="资源可用区")
parser.add_argument("--resource_id", type=str, help="资源ID")
parser.add_argument("--resource_name", type=str, help="资源名称")
parser.add_argument("--resource_type", type=str, help="资源类型")
parser.add_argument("--sort", type=str, help="排序")
parser.add_argument("--start_time", type=str, help="开始时间")
parser.add_argument("--status", type=str, help="状态")
parser.add_argument("--vault_id", type=str, help="存储库ID,可通过 list_vault.py 获取")
parser.add_argument("--enterprise_project_id", type=str, help="企业项目ID")
parser.add_argument("--own_type", type=str, help="所属类型")
parser.add_argument("--member_status", type=str, help="成员状态")
parser.add_argument("--parent_id", type=str, help="父备份ID")
parser.add_argument("--used_percent", type=str, help="使用百分比")
parser.add_argument("--show_replication", type=bool, help="是否显示复制")
parser.add_argument("--incremental", type=bool, help="是否增量备份")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(backups):
total = len(backups)
if Offset >= total:
print(f"查询结果为空\n\n备份列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"id\tname\tstatus\tresource_type\tresource_name\tresource_size(GB)\tvault_id\timage_type\tcreated_at\tincremental\n"
for i in range(Offset, min(total, Offset + 50)):
backup = backups[i]
bid = getattr(backup, 'id', '')
name = getattr(backup, 'name', '')
status = getattr(backup, 'status', '')
resource_type = getattr(backup, 'resource_type', '')
resource_name = getattr(backup, 'resource_name', '')
resource_size = getattr(backup, 'resource_size', '')
vault_id = getattr(backup, 'vault_id', '')
image_type = getattr(backup, 'image_type', '')
created_at = getattr(backup, 'created_at', '')
incremental = getattr(backup, 'incremental', '')
output += f"{bid}\t{name}\t{status}\t{resource_type}\t{resource_name}\t{resource_size}\t{vault_id}\t{image_type}\t{created_at}\t{incremental}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n备份列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListBackupsRequest()
request.limit = args.limit
if args.checkpoint_id:
request.checkpoint_id = args.checkpoint_id
if args.dec:
request.dec = args.dec
if args.end_time:
request.end_time = args.end_time
if args.image_type:
request.image_type = args.image_type
if args.marker:
request.marker = args.marker
if args.name:
request.name = args.name
if args.resource_az:
request.resource_az = args.resource_az
if args.resource_id:
request.resource_id = args.resource_id
if args.resource_name:
request.resource_name = args.resource_name
if args.resource_type:
request.resource_type = args.resource_type
if args.sort:
request.sort = args.sort
if args.start_time:
request.start_time = args.start_time
if args.status:
request.status = args.status
if args.vault_id:
request.vault_id = args.vault_id
if args.enterprise_project_id:
request.enterprise_project_id = args.enterprise_project_id
if args.own_type:
request.own_type = args.own_type
if args.member_status:
request.member_status = args.member_status
if args.parent_id:
request.parent_id = args.parent_id
if args.used_percent:
request.used_percent = args.used_percent
if args.show_replication:
request.show_replication = args.show_replication
if args.incremental:
request.incremental = args.incremental
response = client.list_backups(request)
backups = getattr(response, 'backups', []) or []
count = getattr(response, 'count', 0)
if not backups:
print(f"没有找到备份 (区域: {Region})")
exit(0)
render(backups)
except Exception as e:
print(f"cbr.list_backups 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListDomainProjectsRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询租户项目列表")
parser.add_argument("--project_id", type=str, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--domain_name", type=str, required=True, help="租户名称")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListDomainProjectsRequest()
request.domain_name = args.domain_name
response = client.list_domain_projects(request)
projects = getattr(response, 'projects', []) or []
if not projects:
print(f"没有找到域项目 (区域: {Region})")
exit(0)
output = f"project_id\tproject_name\n"
for project in projects:
project_id = getattr(project, 'project_id', '')
project_name = getattr(project, 'project_name', '')
output += f"{project_id}\t{project_name}\n"
print(output)
except Exception as e:
print(f"cbr.list_domain_projects 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListExternalVaultRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 外部存储库列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--external_project_id", type=str, required=True, help="其他区域的项目ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--limit", type=int, default=1000, help="返回结果个数限制,默认1000")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
parser.add_argument("--protect_type", type=str, help="保护类型")
parser.add_argument("--region_id", type=str, required=True, help="区域ID")
parser.add_argument("--objcet_type", type=str, help="资源类型(注意:SDK原始拼写为objcet_type)")
parser.add_argument("--cloud_type", type=str, help="云类型")
parser.add_argument("--vault_id", type=str, help="存储库ID")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(vaults):
total = len(vaults)
if Offset >= total:
print(f"查询结果为空\n\n外部存储库列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"id\tname\tstatus\tobject_type\tprotect_type\tsize(GB)\tused(MB)\tcreated_at\tavailability_zone\n"
for i in range(Offset, min(total, Offset + 50)):
vault = vaults[i]
vid = getattr(vault, 'id', '')
name = getattr(vault, 'name', '')
created_at = getattr(vault, 'created_at', '')
availability_zone = getattr(vault, 'availability_zone', '')
billing = getattr(vault, 'billing', None)
if billing:
status = getattr(billing, 'status', '')
object_type = getattr(billing, 'object_type', '')
protect_type = getattr(billing, 'protect_type', '')
size = getattr(billing, 'size', '')
used = getattr(billing, 'used', '')
else:
status = ''
object_type = ''
protect_type = ''
size = ''
used = ''
output += f"{vid}\t{name}\t{status}\t{object_type}\t{protect_type}\t{size}\t{used}\t{created_at}\t{availability_zone}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n外部存储库列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListExternalVaultRequest()
request.external_project_id = args.external_project_id
if args.limit:
request.limit = args.limit
if args.protect_type:
request.protect_type = args.protect_type
if args.region_id:
request.region_id = args.region_id
if args.objcet_type:
request.objcet_type = args.objcet_type
if args.cloud_type:
request.cloud_type = args.cloud_type
if args.vault_id:
request.vault_id = args.vault_id
response = client.list_external_vault(request)
vaults = getattr(response, 'vaults', []) or []
count = getattr(response, 'count', 0)
if not vaults:
print(f"没有找到外部存储库 (区域: {Region})")
exit(0)
render(vaults)
except Exception as e:
print(f"cbr.list_external_vault 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListFeaturesRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 特性列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--limit", type=int, help="返回结果个数限制")
parser.add_argument("--offset", type=int, help="偏移量")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListFeaturesRequest()
if args.limit:
request.limit = args.limit
if args.offset:
request.offset = args.offset
response = client.list_features(request)
body = getattr(response, 'body', {})
print(body)
except Exception as e:
print(f"cbr.list_features 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListOpLogsRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 任务列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--end_time", type=str, help="结束时间")
parser.add_argument("--limit", type=int, default=1000, help="返回结果个数限制,默认1000")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
parser.add_argument("--operation_type", type=str, help="任务类型")
parser.add_argument("--provider_id", type=str, help="备份提供商ID")
parser.add_argument("--resource_id", type=str, help="资源ID")
parser.add_argument("--resource_name", type=str, help="资源名称")
parser.add_argument("--start_time", type=str, help="开始时间")
parser.add_argument("--status", type=str, help="状态")
parser.add_argument("--vault_id", type=str, help="存储库ID,可通过 list_vault.py 获取")
parser.add_argument("--vault_name", type=str, help="存储库名称")
parser.add_argument("--enterprise_project_id", type=str, help="企业项目ID")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(op_logs):
total = len(op_logs)
if Offset >= total:
print(f"查询结果为空\n\n任务列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"id\toperation_type\tstatus\tprovider_id\tvault_id\tvault_name\tcreated_at\n"
for i in range(Offset, min(total, Offset + 50)):
log = op_logs[i]
oid = getattr(log, 'id', '')
operation_type = getattr(log, 'operation_type', '')
status = getattr(log, 'status', '')
provider_id = getattr(log, 'provider_id', '')
vault_id = getattr(log, 'vault_id', '')
vault_name = getattr(log, 'vault_name', '')
created_at = getattr(log, 'created_at', '')
output += f"{oid}\t{operation_type}\t{status}\t{provider_id}\t{vault_id}\t{vault_name}\t{created_at}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n任务列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListOpLogsRequest()
request.limit = args.limit
if args.end_time:
request.end_time = args.end_time
if args.operation_type:
request.operation_type = args.operation_type
if args.provider_id:
request.provider_id = args.provider_id
if args.resource_id:
request.resource_id = args.resource_id
if args.resource_name:
request.resource_name = args.resource_name
if args.start_time:
request.start_time = args.start_time
if args.status:
request.status = args.status
if args.vault_id:
request.vault_id = args.vault_id
if args.vault_name:
request.vault_name = args.vault_name
if args.enterprise_project_id:
request.enterprise_project_id = args.enterprise_project_id
response = client.list_op_logs(request)
op_logs = getattr(response, 'operation_logs', []) or []
count = getattr(response, 'count', 0)
if not op_logs:
print(f"没有找到任务(区域: {Region})")
exit(0)
render(op_logs)
except Exception as e:
print(f"cbr.list_op_logs 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListOrganizationPoliciesRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 组织策略列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--operation_type", type=str, required=True, help="组织策略类型:备份(backup)、复制(replication)")
parser.add_argument("--limit", type=int, default=1000, help="返回结果个数限制,默认1000")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(policies):
total = len(policies)
if Offset >= total:
print(f"查询结果为空\n\n组织策略列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"id\tname\toperation_type\tpolicy_enabled\tstatus\n"
for i in range(Offset, min(total, Offset + 50)):
policy = policies[i]
pid = getattr(policy, 'id', '')
name = getattr(policy, 'name', '')
operation_type = getattr(policy, 'operation_type', '')
policy_enabled = getattr(policy, 'policy_enabled', '')
status = getattr(policy, 'status', '')
output += f"{pid}\t{name}\t{operation_type}\t{policy_enabled}\t{status}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n组织策略列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListOrganizationPoliciesRequest()
if args.operation_type:
request.operation_type = args.operation_type
if args.limit:
request.limit = args.limit
response = client.list_organization_policies(request)
policies = getattr(response, 'policies', []) or []
count = getattr(response, 'count', 0)
if not policies:
print(f"没有找到组织策略 (区域: {Region})")
exit(0)
render(policies)
except Exception as e:
print(f"cbr.list_organization_policies 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListOrganizationPolicyDetailRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询组织策略部署状态列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--organization_policy_id", type=str, required=True, help="组织策略ID")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListOrganizationPolicyDetailRequest()
request.organization_policy_id = args.organization_policy_id
response = client.list_organization_policy_detail(request)
policies = getattr(response, 'policies', []) or []
count = getattr(response, 'count', 0)
if not policies:
print(f"没有找到组织策略详情 (区域: {Region})")
exit(0)
output = f"policy_id\tdomain_id\tproject_id\tstatus\n"
for policy in policies:
policy_id = getattr(policy, 'policy_id', '')
domain_id = getattr(policy, 'domain_id', '')
project_id = getattr(policy, 'project_id', '')
status = getattr(policy, 'status', '')
output += f"{policy_id}\t{domain_id}\t{project_id}\t{status}\n"
print(output)
except Exception as e:
print(f"cbr.list_organization_policy_detail 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListPoliciesRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 策略列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--operation_type", type=str, help="策略类型:备份(backup)、复制(replication)")
parser.add_argument("--vault_id", type=str, help="存储库ID,可通过 list_vault.py 获取")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListPoliciesRequest()
if args.operation_type:
request.operation_type = args.operation_type
if args.vault_id:
request.vault_id = args.vault_id
response = client.list_policies(request)
policies = getattr(response, 'policies', []) or []
count = getattr(response, 'count', 0)
if not policies:
print(f"没有找到策略 (区域: {Region})")
exit(0)
output = f"id\tname\tenabled\toperation_type\tassociated_vaults_count\n"
for policy in policies:
pid = getattr(policy, 'id', '')
name = getattr(policy, 'name', '')
enabled = getattr(policy, 'enabled', '')
operation_type = getattr(policy, 'operation_type', '')
associated_vaults = getattr(policy, 'associated_vaults', []) or []
output += f"{pid}\t{name}\t{enabled}\t{operation_type}\t{len(associated_vaults)}\n"
print(output)
except Exception as e:
print(f"cbr.list_policies 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListProjectsRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 项目列表")
parser.add_argument("--project_id", type=str, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListProjectsRequest()
response = client.list_projects(request)
projects = getattr(response, 'projects', []) or []
if not projects:
print(f"没有找到项目 (区域: {Region})")
exit(0)
output = f"id\tname\tdomain_id\tenabled\n"
for project in projects:
pid = getattr(project, 'id', '')
name = getattr(project, 'name', '')
domain_id = getattr(project, 'domain_id', '')
enabled = getattr(project, 'enabled', '')
output += f"{pid}\t{name}\t{domain_id}\t{enabled}\n"
print(output)
except Exception as e:
print(f"cbr.list_projects 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListProtectableRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 可保护资源列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--protectable_type", type=str, required=True, help="可保护资源类型,取值: server(云服务器类型), disk(云硬盘类型), turbo(turbo类型), workspace(workspace类型),workspace_v2(workspace_v2类型)")
parser.add_argument("--limit", type=int, default=1000, help="返回结果个数限制,默认1000")
parser.add_argument("--marker", type=str, help="分页标记")
parser.add_argument("--name", type=str, help="资源名称")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
parser.add_argument("--status", type=str, help="状态")
parser.add_argument("--id", type=str, help="根据资源id过滤")
parser.add_argument("--server_id", type=str, help="云服务器ID")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(instances):
total = len(instances)
if Offset >= total:
print(f"查询结果为空\n\n可保护资源列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"id\tname\ttype\tsize(GB)\tstatus\n"
for i in range(Offset, min(total, Offset + 50)):
inst = instances[i]
iid = getattr(inst, 'id', '')
name = getattr(inst, 'name', '')
itype = getattr(inst, 'type', '')
size = getattr(inst, 'size', '')
status = getattr(inst, 'status', '')
output += f"{iid}\t{name}\t{itype}\t{size}\t{status}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n可保护资源列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ListProtectableRequest()
request.protectable_type = args.protectable_type
request.limit = args.limit
if args.marker:
request.marker = args.marker
if args.name:
request.name = args.name
if args.status:
request.status = args.status
if args.id:
request.id = args.id
if args.server_id:
request.server_id = args.server_id
response = client.list_protectable(request)
instances = getattr(response, 'instances', []) or []
if not instances:
print(f"没有找到可保护资源 (区域: {Region})")
exit(0)
render(instances)
except Exception as e:
print(f"cbr.list_protectable 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ListVaultRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 存储库列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--limit", type=int, default=1000, help="返回结果个数限制,默认1000")
parser.add_argument("--name", type=str, help="存储库名称")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
parser.add_argument("--cloud_type", type=str, help="云类型")
parser.add_argument("--protect_type", type=str, help="保护类型")
parser.add_argument("--object_type", type=str, help="对象类型:云服务器(server),云硬盘(disk),文件系统(turbo),云桌面(workspace),VMware(vmware),关系型数据库(rds),文件(file)")
parser.add_argument("--enterprise_project_id", type=str, help="企业项目id或all_granted_eps,可通过 ../eps/list_enterprise_projects.py 获取")
parser.add_argument("--id", type=str, help="存储库ID,多个以英文逗号分隔")
parser.add_argument("--policy_id", type=str, help="策略ID,可通过 list_policies.py 获取")
parser.add_argument("--status", type=str, help="状态")
parser.add_argument("--resource_ids", type=str, help="资源id,支持多资源,以英文逗号分隔")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(vaults):
total = len(vaults)
if Offset >= total:
print(f"查询结果为空\n\n存储库列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"id\tname\tstatus\tobject_type\tprotect_type\tsize(GB)\tused(MB)\tcreated_at\tavailability_zone\n"
for i in range(Offset, min(total, Offset + 50)):
vault = vaults[i]
vid = getattr(vault, 'id', '')
name = getattr(vault, 'name', '')
created_at = getattr(vault, 'created_at', '')
availability_zone = getattr(vault, 'availability_zone', '')
billing = getattr(vault, 'billing', None)
if billing:
status = getattr(billing, 'status', '')
object_type = getattr(billing, 'object_type', '')
protect_type = getattr(billing, 'protect_type', '')
size = getattr(billing, 'size', '')
used = getattr(billing, 'used', '')
else:
status = ''
object_type = ''
protect_type = ''
size = ''
used = ''
output += f"{vid}\t{name}\t{status}\t{object_type}\t{protect_type}\t{size}\t{used}\t{created_at}\t{availability_zone}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n存储库列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
all_vaults = []
limit = args.limit
request = ListVaultRequest()
request.limit = limit
if args.name:
request.name = args.name
if args.cloud_type:
request.cloud_type = args.cloud_type
if args.protect_type:
request.protect_type = args.protect_type
if args.object_type:
request.object_type = args.object_type
if args.enterprise_project_id:
request.enterprise_project_id = args.enterprise_project_id
if args.id:
request.id = args.id
if args.policy_id:
request.policy_id = args.policy_id
if args.status:
request.status = args.status
if args.resource_ids:
request.resource_ids = args.resource_ids
response = client.list_vault(request)
vaults = getattr(response, 'vaults', []) or []
count = getattr(response, 'count', 0)
if not vaults:
print(f"没有找到存储库 (区域: {Region})")
exit(0)
render(vaults)
except Exception as e:
print(f"cbr.list_vault 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowAgentRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 客户端详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--agent_id", type=str, required=True, help="客户端ID,可通过 list_agent.py 获取")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowAgentRequest()
request.agent_id = args.agent_id
response = client.show_agent(request)
agent = getattr(response, 'agent', None)
if not agent:
print(f"没有找到客户端 (区域: {Region}, 客户端 ID: {args.agent_id})")
exit(0)
output = ""
output += f"agent_id: {getattr(agent, 'agent_id', '')}\n"
output += f"agent_version: {getattr(agent, 'agent_version', '')}\n"
output += f"agent_type: {getattr(agent, 'agent_type', '')}\n"
output += f"host_name: {getattr(agent, 'host_name', '')}\n"
output += f"host_nickname: {getattr(agent, 'host_nickname', '')}\n"
output += f"host_ip: {getattr(agent, 'host_ip', '')}\n"
output += f"host_os: {getattr(agent, 'host_os', '')}\n"
output += f"status: {getattr(agent, 'status', '')}\n"
output += f"last_active_time: {getattr(agent, 'last_active_time', '')}\n"
output += f"created_at: {getattr(agent, 'created_at', '')}\n"
output += f"updated_at: {getattr(agent, 'updated_at', '')}\n"
paths = getattr(agent, 'paths', []) or []
if paths:
output += f"\npaths ({len(paths)}):\n"
for path in paths:
output += f" id: {getattr(path, 'id', '')}\n"
output += f" dir_path: {getattr(path, 'dir_path', '')}\n"
output += f" status: {getattr(path, 'status', '')}\n"
exclude_paths = getattr(path, 'exclude_paths', []) or []
output += f" exclude_paths: {exclude_paths}\n"
print(output)
except Exception as e:
print(f"cbr.show_agent 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowBackupRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 备份详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--backup_id", type=str, required=True, help="备份ID,可通过 list_backups.py 获取")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowBackupRequest()
request.backup_id = args.backup_id
response = client.show_backup(request)
backup = getattr(response, 'backup', None)
if not backup:
print(f"没有找到备份 (区域: {Region}, 备份 ID: {args.backup_id})")
exit(0)
output = ""
output += f"id: {getattr(backup, 'id', '')}\n"
output += f"name: {getattr(backup, 'name', '')}\n"
output += f"description: {getattr(backup, 'description', '')}\n"
output += f"status: {getattr(backup, 'status', '')}\n"
output += f"resource_id: {getattr(backup, 'resource_id', '')}\n"
output += f"resource_name: {getattr(backup, 'resource_name', '')}\n"
output += f"resource_type: {getattr(backup, 'resource_type', '')}\n"
output += f"resource_size: {getattr(backup, 'resource_size', '')}\n"
output += f"vault_id: {getattr(backup, 'vault_id', '')}\n"
output += f"image_type: {getattr(backup, 'image_type', '')}\n"
output += f"incremental: {getattr(backup, 'incremental', '')}\n"
output += f"created_at: {getattr(backup, 'created_at', '')}\n"
output += f"expired_at: {getattr(backup, 'expired_at', '')}\n"
output += f"protected_at: {getattr(backup, 'protected_at', '')}\n"
output += f"checkpoint_id: {getattr(backup, 'checkpoint_id', '')}\n"
output += f"enterprise_project_id: {getattr(backup, 'enterprise_project_id', '')}\n"
output += f"provider_id: {getattr(backup, 'provider_id', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_backup 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowCheckpointRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 还原点详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--checkpoint_id", type=str, required=True, help="还原点ID,可通过 list_backups.py 获取")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowCheckpointRequest()
request.checkpoint_id = args.checkpoint_id
response = client.show_checkpoint(request)
checkpoint = getattr(response, 'checkpoint', None)
if not checkpoint:
print(f"没有找到还原点 (区域: {Region}, 还原点 ID: {args.checkpoint_id})")
exit(0)
output = ""
output += f"id: {getattr(checkpoint, 'id', '')}\n"
output += f"status: {getattr(checkpoint, 'status', '')}\n"
output += f"project_id: {getattr(checkpoint, 'project_id', '')}\n"
output += f"created_at: {getattr(checkpoint, 'created_at', '')}\n"
extra_info = getattr(checkpoint, 'extra_info', None)
if extra_info:
output += f"\nextra_info:\n"
output += f" name: {getattr(extra_info, 'name', '')}\n"
output += f" description: {getattr(extra_info, 'description', '')}\n"
output += f" retention_duration: {getattr(extra_info, 'retention_duration', '')}\n"
vault = getattr(checkpoint, 'vault', None)
if vault:
output += f"\nvault:\n"
output += f" id: {getattr(vault, 'id', '')}\n"
output += f" name: {getattr(vault, 'name', '')}\n"
resources = getattr(vault, 'resources', []) or []
if resources:
output += f" resources ({len(resources)}):\n"
for res in resources:
output += f" id: {getattr(res, 'id', '')}\n"
output += f" name: {getattr(res, 'name', '')}\n"
output += f" type: {getattr(res, 'type', '')}\n"
output += f" protect_status: {getattr(res, 'protect_status', '')}\n"
output += f" resource_size: {getattr(res, 'resource_size', '')}\n"
output += f" backup_size: {getattr(res, 'backup_size', '')}\n"
output += f" backup_count: {getattr(res, 'backup_count', '')}\n"
extra = getattr(res, 'extra_info', '')
if extra:
output += f" extra_info: {extra}\n"
skipped_resources = getattr(vault, 'skipped_resources', []) or []
if skipped_resources:
output += f" skipped_resources ({len(skipped_resources)}):\n"
for sk in skipped_resources:
output += f" id: {getattr(sk, 'id', '')}\n"
output += f" name: {getattr(sk, 'name', '')}\n"
output += f" type: {getattr(sk, 'type', '')}\n"
output += f" code: {getattr(sk, 'code', '')}\n"
output += f" reason: {getattr(sk, 'reason', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_checkpoint 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowDomainRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询租户信息")
parser.add_argument("--project_id", type=str, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--source_project_id", type=str, required=True, help="源项目ID")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowDomainRequest()
request.source_project_id = args.source_project_id
response = client.show_domain(request)
output = ""
output += f"project_name: {getattr(response, 'project_name', '')}\n"
output += f"project_id: {getattr(response, 'project_id', '')}\n"
output += f"domain_id: {getattr(response, 'domain_id', '')}\n"
output += f"domain_name: {getattr(response, 'domain_name', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_domain 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowFeatureRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 特性详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--feature_key", type=str, required=True, help="特性key,当前支持:replication.enable、replication.source_region、replication.destination_regions、replication.destination_dgw_regions、features.backup_double_az")
parser.add_argument("--limit", type=int, help="返回结果个数限制")
parser.add_argument("--offset", type=int, help="偏移量")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowFeatureRequest()
request.feature_key = args.feature_key
if args.limit:
request.limit = args.limit
if args.offset:
request.offset = args.offset
response = client.show_feature(request)
body = getattr(response, 'body', {})
print(body)
except Exception as e:
print(f"cbr.show_feature 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowMemberDetailRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 备份成员详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--backup_id", type=str, required=True, help="备份ID")
parser.add_argument("--member_id", type=str, required=True, help="成员id,为接收方的project_id")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowMemberDetailRequest()
request.backup_id = args.backup_id
request.member_id = args.member_id
response = client.show_member_detail(request)
member = getattr(response, 'member', None)
if not member:
print(f"没有找到备份成员 (区域: {Region}, 备份 ID: {args.backup_id}, 成员 ID: {args.member_id})")
exit(0)
output = ""
output += f"id: {getattr(member, 'id', '')}\n"
output += f"status: {getattr(member, 'status', '')}\n"
output += f"backup_id: {getattr(member, 'backup_id', '')}\n"
output += f"image_id: {getattr(member, 'image_id', '')}\n"
output += f"dest_project_id: {getattr(member, 'dest_project_id', '')}\n"
output += f"vault_id: {getattr(member, 'vault_id', '')}\n"
output += f"created_at: {getattr(member, 'created_at', '')}\n"
output += f"updated_at: {getattr(member, 'updated_at', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_member_detail 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowMembersDetailRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 备份成员列表")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--backup_id", type=str, required=True, help="备份ID,可通过 list_backups.py 获取")
parser.add_argument("--dest_project_id", type=str, help="接受备份恢复的目标项目ID")
parser.add_argument("--image_id", type=str, help="接受备份共享的镜像ID")
parser.add_argument("--status", type=str, help="状态")
parser.add_argument("--vault_id", type=str, help="存储库ID")
parser.add_argument("--limit", type=int, help="返回结果个数限制")
parser.add_argument("--marker", type=str, help="分页标记")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
parser.add_argument("--sort", type=str, help="排序")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(members):
total = len(members)
if Offset >= total:
print(f"查询结果为空\n\n成员列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"id\tstatus\tbackup_id\tdest_project_id\tvault_id\tcreated_at\n"
for i in range(Offset, min(total, Offset + 50)):
member = members[i]
mid = getattr(member, 'id', '')
status = getattr(member, 'status', '')
backup_id = getattr(member, 'backup_id', '')
dest_project_id = getattr(member, 'dest_project_id', '')
vault_id = getattr(member, 'vault_id', '')
created_at = getattr(member, 'created_at', '')
output += f"{mid}\t{status}\t{backup_id}\t{dest_project_id}\t{vault_id}\t{created_at}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n成员列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowMembersDetailRequest()
request.backup_id = args.backup_id
if args.dest_project_id:
request.dest_project_id = args.dest_project_id
if args.image_id:
request.image_id = args.image_id
if args.status:
request.status = args.status
if args.vault_id:
request.vault_id = args.vault_id
if args.limit:
request.limit = args.limit
if args.marker:
request.marker = args.marker
if args.sort:
request.sort = args.sort
response = client.show_members_detail(request)
members = getattr(response, 'members', []) or []
count = getattr(response, 'count', 0)
if not members:
print(f"没有找到备份成员 (区域: {Region})")
exit(0)
render(members)
except Exception as e:
print(f"cbr.show_members_detail 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowMetadataRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 备份元数据")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--backup_id", type=str, required=True, help="备份ID")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowMetadataRequest()
request.backup_id = args.backup_id
response = client.show_metadata(request)
output = ""
output += f"backup_id: {getattr(response, 'backup_id', '')}\n"
output += f"backups: {getattr(response, 'backups', '')}\n"
output += f"flavor: {getattr(response, 'flavor', '')}\n"
floatingips = getattr(response, 'floatingips', []) or []
output += f"floatingips: {floatingips}\n"
output += f"interface: {getattr(response, 'interface', '')}\n"
ports = getattr(response, 'ports', []) or []
output += f"ports: {ports}\n"
output += f"server: {getattr(response, 'server', '')}\n"
volumes = getattr(response, 'volumes', []) or []
output += f"volumes: {volumes}\n"
print(output)
except Exception as e:
print(f"cbr.show_metadata 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowMigrateStatusRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 迁移状态")
parser.add_argument("--project_id", type=str, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--all_regions", type=bool, help="是否查询所有区域")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowMigrateStatusRequest()
if args.all_regions:
request.all_regions = args.all_regions
response = client.show_migrate_status(request)
output = ""
status = getattr(response, 'status', '')
output += f"status: {status}\n"
project_status = getattr(response, 'project_status', []) or []
if project_status:
output += f"\nproject_status ({len(project_status)}):\n"
for ps in project_status:
output += f" {ps}\n"
print(output)
except Exception as e:
print(f"cbr.show_migrate_status 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowOpLogRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 任务详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--operation_log_id", type=str, required=True, help="任务ID,可通过 list_op_logs.py 获取")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowOpLogRequest()
request.operation_log_id = args.operation_log_id
response = client.show_op_log(request)
op_log = getattr(response, 'operation_log', None)
if not op_log:
print(f"没有找到任务 (区域: {Region}, 任务 ID: {args.operation_log_id})")
exit(0)
output = ""
output += f"id: {getattr(op_log, 'id', '')}\n"
output += f"operation_type: {getattr(op_log, 'operation_type', '')}\n"
output += f"status: {getattr(op_log, 'status', '')}\n"
output += f"provider_id: {getattr(op_log, 'provider_id', '')}\n"
output += f"vault_id: {getattr(op_log, 'vault_id', '')}\n"
output += f"vault_name: {getattr(op_log, 'vault_name', '')}\n"
output += f"project_id: {getattr(op_log, 'project_id', '')}\n"
output += f"policy_id: {getattr(op_log, 'policy_id', '')}\n"
output += f"checkpoint_id: {getattr(op_log, 'checkpoint_id', '')}\n"
output += f"created_at: {getattr(op_log, 'created_at', '')}\n"
output += f"started_at: {getattr(op_log, 'started_at', '')}\n"
output += f"ended_at: {getattr(op_log, 'ended_at', '')}\n"
output += f"updated_at: {getattr(op_log, 'updated_at', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_op_log 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowOrganizationPolicyRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 组织策略详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--organization_policy_id", type=str, required=True, help="组织策略ID")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowOrganizationPolicyRequest()
request.organization_policy_id = args.organization_policy_id
response = client.show_organization_policy(request)
policy = getattr(response, 'policy', None)
if not policy:
print(f"没有找到组织策略 (区域: {Region}, 组织策略 ID: {args.organization_policy_id})")
exit(0)
output = ""
output += f"id: {getattr(policy, 'id', '')}\n"
output += f"name: {getattr(policy, 'name', '')}\n"
output += f"description: {getattr(policy, 'description', '')}\n"
output += f"operation_type: {getattr(policy, 'operation_type', '')}\n"
output += f"domain_id: {getattr(policy, 'domain_id', '')}\n"
output += f"domain_name: {getattr(policy, 'domain_name', '')}\n"
output += f"policy_enabled: {getattr(policy, 'policy_enabled', '')}\n"
output += f"status: {getattr(policy, 'status', '')}\n"
output += f"effective_scope: {getattr(policy, 'effective_scope', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_organization_policy 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowPolicyRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 策略详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--policy_id", type=str, required=True, help="策略ID,可通过 list_policies.py 获取")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowPolicyRequest()
request.policy_id = args.policy_id
response = client.show_policy(request)
policy = getattr(response, 'policy', None)
if not policy:
print(f"没有找到策略 (区域: {Region}, 策略 ID: {args.policy_id})")
exit(0)
output = ""
output += f"id: {getattr(policy, 'id', '')}\n"
output += f"name: {getattr(policy, 'name', '')}\n"
output += f"enabled: {getattr(policy, 'enabled', '')}\n"
output += f"operation_type: {getattr(policy, 'operation_type', '')}\n"
output += f"policy_type: {getattr(policy, 'policy_type', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_policy 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowProtectableRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 可保护资源详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--protectable_type", type=str, required=True, help="可保护性类型,可选参数为server,disk,turbo,workspace和workspace_v2")
parser.add_argument("--instance_id", type=str, required=True, help="资源实例ID")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowProtectableRequest()
request.protectable_type = args.protectable_type
request.instance_id = args.instance_id
response = client.show_protectable(request)
instance = getattr(response, 'instance', None)
if not instance:
print(f"没有找到可保护资源 (区域: {Region}, 实例 ID: {args.instance_id})")
exit(0)
output = ""
output += f"id: {getattr(instance, 'id', '')}\n"
output += f"name: {getattr(instance, 'name', '')}\n"
output += f"type: {getattr(instance, 'type', '')}\n"
output += f"size: {getattr(instance, 'size', '')}\n"
output += f"status: {getattr(instance, 'status', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_protectable 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowReplicationCapabilitiesRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 复制能力")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowReplicationCapabilitiesRequest()
response = client.show_replication_capabilities(request)
regions = getattr(response, 'regions', []) or []
if not regions:
print(f"没有找到复制能力信息 (区域: {Region})")
exit(0)
output = f"name\treplication_destinations\n"
for region in regions:
name = getattr(region, 'name', '')
destinations = getattr(region, 'replication_destinations', []) or []
output += f"{name}\t{', '.join(destinations)}\n"
print(output)
except Exception as e:
print(f"cbr.show_replication_capabilities 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowStorageUsageRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 存储使用情况")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--limit", type=int, help="返回结果个数限制")
parser.add_argument("--offset", type=int, help="本地渲染分页偏移量,从 0 开始")
parser.add_argument("--resource_id", type=str, help="资源ID")
parser.add_argument("--resource_type", type=str, help="资源类型")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.offset is not None:
Offset = args.offset
if Offset < 0:
Offset = 0
def render(storage_usage, resource_count):
total = len(storage_usage)
if Offset >= total:
print(f"查询结果为空\n\n存储使用列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"resource_count: {resource_count}\n\n"
output += f"resource_id\tresource_name\tresource_type\tbackup_count\tbackup_size(GB)\tbackup_size_multiaz\n"
for i in range(Offset, min(total, Offset + 50)):
su = storage_usage[i]
resource_id = getattr(su, 'resource_id', '')
resource_name = getattr(su, 'resource_name', '')
resource_type = getattr(su, 'resource_type', '')
backup_count = getattr(su, 'backup_count', 0)
backup_size = getattr(su, 'backup_size', 0)
backup_size_multiaz = getattr(su, 'backup_size_multiaz', 0)
output += f"{resource_id}\t{resource_name}\t{resource_type}\t{backup_count}\t{backup_size}\t{backup_size_multiaz}\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n存储使用列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowStorageUsageRequest()
if args.limit:
request.limit = args.limit
if args.resource_id:
request.resource_id = args.resource_id
if args.resource_type:
request.resource_type = args.resource_type
response = client.show_storage_usage(request)
resource_count = getattr(response, 'resource_count', 0)
storage_usage = getattr(response, 'storage_usage', []) or []
if not storage_usage:
print(f"没有找到存储使用信息 (区域: {Region})")
exit(0)
render(storage_usage, resource_count)
except Exception as e:
print(f"cbr.show_storage_usage 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowSummaryRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 总容量和已使用容量")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowSummaryRequest()
response = client.show_summary(request)
size = getattr(response, 'size', 0)
used_size = getattr(response, 'used_size', 0)
print(f"总容量(GB): {size}\n已使用(GB): {used_size}")
except Exception as e:
print(f"cbr.show_summary 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowVaultProjectTagRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 存储库项目标签")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowVaultProjectTagRequest()
response = client.show_vault_project_tag(request)
tags = getattr(response, 'tags', []) or []
if not tags:
print(f"没有找到项目标签 (区域: {Region})")
exit(0)
output = ""
for tag in tags:
output += f"{tag}\n"
print(output)
except Exception as e:
print(f"cbr.show_vault_project_tag 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model.show_vault_resource_instances_request import ShowVaultResourceInstancesRequest
from huaweicloudsdkcbr.v1.model.vault_resource_instances_req import VaultResourceInstancesReq
from huaweicloudsdkcbr.v1.model.tags_req import TagsReq
from huaweicloudsdkcbr.v1.model.match import Match
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
Offset = 0
parser = argparse.ArgumentParser(description="查询 CBR 存储库标签资源实例")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--action", type=str, default="filter", help="操作标识,取值范围:filter(过滤)/count(计数)")
parser.add_argument("--limit", type=str, default="1000", help="返回结果个数限制,默认1000")
parser.add_argument("--offset", type=str, default="0", help="索引位置,从0开始")
parser.add_argument("--tags", type=str, help="标签过滤条件(与关系),格式: key1=value1|value2,key2=value3")
parser.add_argument("--tags_any", type=str, help="标签过滤条件(或关系),格式同tags")
parser.add_argument("--not_tags", type=str, help="标签排除条件(与关系),格式同tags")
parser.add_argument("--not_tags_any", type=str, help="标签排除条件(或关系),格式同tags")
parser.add_argument("--without_any_tag", action="store_true", help="不包含任意标签的资源")
parser.add_argument("--cloud_type", type=str, help="云类型: public/hybrid")
parser.add_argument("--object_type", type=str, help="对象类型: server/disk/turbo/workspace/vmware/rds/file")
parser.add_argument("--matches", type=str, help="字段匹配条件,格式: key1=value1,key2=value2")
parser.add_argument("--render_offset", type=int, help="本地渲染分页偏移量,从 0 开始")
args = parser.parse_args()
if args.region is not None:
Region = args.region
if args.render_offset is not None:
Offset = args.render_offset
if Offset < 0:
Offset = 0
def parse_tags_str(tags_str):
result = []
if not tags_str:
return result
for part in tags_str.split(','):
if '=' in part:
k, v = part.split('=', 1)
values = [x.strip() for x in v.split('|') if x.strip()]
result.append(TagsReq(key=k.strip(), values=values))
return result
def render(resources, total_count):
total = len(resources)
if Offset >= total:
print(f"查询结果为空\n\n资源实例列表共 {total} 个, 序号从 0 开始, offset必须 < {total}")
exit(0)
output = f"total_count: {total_count}\n\n"
for i in range(Offset, min(total, Offset + 50)):
res = resources[i]
resource_id = getattr(res, 'resource_id', '')
resource_name = getattr(res, 'resource_name', '')
output += f"resource_id: {resource_id}\n"
output += f"resource_name: {resource_name}\n"
resource_detail = getattr(res, 'resource_detail', None)
if resource_detail:
vault = getattr(resource_detail, 'vault', None)
if vault:
vault_billing = getattr(vault, 'billing', None)
output += f" vault.id: {getattr(vault, 'id', '')}\n"
output += f" vault.name: {getattr(vault, 'name', '')}\n"
if vault_billing:
output += f" vault.status: {getattr(vault_billing, 'status', '')}\n"
output += f" vault.object_type: {getattr(vault_billing, 'object_type', '')}\n"
output += f" vault.protect_type: {getattr(vault_billing, 'protect_type', '')}\n"
output += f" vault.size: {getattr(vault_billing, 'size', '')}\n"
output += f" vault.used: {getattr(vault_billing, 'used', '')}\n"
output += "\n"
end = min(total, Offset + 50) - 1
if total > 50 or Offset > 0:
output += f"\n资源实例列表共 {total} 个, 序号从 0 开始,当前显示第 {Offset}~{end} 个\n"
if end + 1 < total:
output += f"可以使用 --render_offset={end + 1} 参数继续获取后续数据"
print(output)
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
req_body = VaultResourceInstancesReq()
req_body.action = args.action
if args.action != "count":
req_body.limit = args.limit
req_body.offset = args.offset
if args.tags:
req_body.tags = parse_tags_str(args.tags)
if args.tags_any:
req_body.tags_any = parse_tags_str(args.tags_any)
if args.not_tags:
req_body.not_tags = parse_tags_str(args.not_tags)
if args.not_tags_any:
req_body.not_tags_any = parse_tags_str(args.not_tags_any)
if args.without_any_tag:
req_body.without_any_tag = True
if args.cloud_type:
req_body.cloud_type = args.cloud_type
if args.object_type:
req_body.object_type = args.object_type
if args.matches:
matches_list = []
for pair in args.matches.split(','):
if '=' in pair:
k, v = pair.split('=', 1)
matches_list.append(Match(key=k.strip(), value=v.strip()))
req_body.matches = matches_list
request = ShowVaultResourceInstancesRequest()
request.body = req_body
response = client.show_vault_resource_instances(request)
resources = getattr(response, 'resources', []) or []
total_count = getattr(response, 'total_count', 0)
if args.action == "count":
print(f"total_count: {total_count}")
exit(0)
if not resources:
print(f"没有找到标签资源实例 (区域: {Region})")
exit(0)
render(resources, total_count)
except Exception as e:
print(f"cbr.show_vault_resource_instances 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowVaultTagRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 存储库标签")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--vault_id", type=str, required=True, help="存储库ID,可通过 list_vault.py 获取")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowVaultTagRequest()
request.vault_id = args.vault_id
response = client.show_vault_tag(request)
output = ""
tags = getattr(response, 'tags', []) or []
if tags:
output += f"tags ({len(tags)}):\n"
for tag in tags:
key = getattr(tag, 'key', '')
value = getattr(tag, 'value', '')
output += f" {key}: {value}\n"
else:
output += "tags: (none)\n"
sys_tags = getattr(response, 'sys_tags', []) or []
if sys_tags:
output += f"\nsys_tags ({len(sys_tags)}):\n"
for stag in sys_tags:
key = getattr(stag, 'key', '')
value = getattr(stag, 'value', None)
if value is not None:
output += f" {key}: {value}\n"
else:
output += f" {key}\n"
else:
output += "\nsys_tags: (none)\n"
print(output)
except Exception as e:
print(f"cbr.show_vault_tag 查询失败: {e}")
exit(1)
import argparse
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from config import load_credentials, build_http_config
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1 import CbrClient
from huaweicloudsdkcbr.v1.model import ShowVaultRequest
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
AK, SK, Region, SecurityToken = load_credentials()
parser = argparse.ArgumentParser(description="查询 CBR 存储库详情")
parser.add_argument("--project_id", type=str, required=True, help="项目 ID")
parser.add_argument("--region", type=str, help="区域,默认 cn-north-4")
parser.add_argument("--vault_id", type=str, required=True, help="存储库ID,可通过 list_vault.py 获取")
args = parser.parse_args()
if args.region is not None:
Region = args.region
try:
http_config = build_http_config()
client = CbrClient.new_builder().with_http_config(http_config).with_credentials(
BasicCredentials(AK, SK, args.project_id) if not SecurityToken else BasicCredentials(AK, SK, args.project_id).with_security_token(SecurityToken)).with_region(CbrRegion.value_of(Region)).build()
if not client:
print(f"无法获取 CBR 客户端")
exit(-1)
request = ShowVaultRequest()
request.vault_id = args.vault_id
response = client.show_vault(request)
vault = getattr(response, 'vault', None)
if not vault:
print(f"没有找到存储库 (区域: {Region}, 存储库 ID: {args.vault_id})")
exit(0)
output = ""
output += f"id: {getattr(vault, 'id', '')}\n"
output += f"name: {getattr(vault, 'name', '')}\n"
output += f"description: {getattr(vault, 'description', '')}\n"
output += f"project_id: {getattr(vault, 'project_id', '')}\n"
output += f"provider_id: {getattr(vault, 'provider_id', '')}\n"
output += f"enterprise_project_id: {getattr(vault, 'enterprise_project_id', '')}\n"
output += f"user_id: {getattr(vault, 'user_id', '')}\n"
output += f"created_at: {getattr(vault, 'created_at', '')}\n"
output += f"availability_zone: {getattr(vault, 'availability_zone', '')}\n"
output += f"auto_bind: {getattr(vault, 'auto_bind', '')}\n"
output += f"auto_expand: {getattr(vault, 'auto_expand', '')}\n"
output += f"smn_notify: {getattr(vault, 'smn_notify', '')}\n"
output += f"threshold: {getattr(vault, 'threshold', '')}\n"
output += f"sys_lock_source_service: {getattr(vault, 'sys_lock_source_service', '')}\n"
output += f"locked: {getattr(vault, 'locked', '')}\n"
billing = getattr(vault, 'billing', None)
if billing:
output += f"\nbilling:\n"
output += f" charging_mode: {getattr(billing, 'charging_mode', '')}\n"
output += f" cloud_type: {getattr(billing, 'cloud_type', '')}\n"
output += f" consistent_level: {getattr(billing, 'consistent_level', '')}\n"
output += f" object_type: {getattr(billing, 'object_type', '')}\n"
output += f" protect_type: {getattr(billing, 'protect_type', '')}\n"
output += f" size: {getattr(billing, 'size', '')}\n"
output += f" used: {getattr(billing, 'used', '')}\n"
output += f" allocated: {getattr(billing, 'allocated', '')}\n"
output += f" status: {getattr(billing, 'status', '')}\n"
output += f" spec_code: {getattr(billing, 'spec_code', '')}\n"
output += f" order_id: {getattr(billing, 'order_id', '')}\n"
output += f" product_id: {getattr(billing, 'product_id', '')}\n"
output += f" storage_unit: {getattr(billing, 'storage_unit', '')}\n"
output += f" frozen_scene: {getattr(billing, 'frozen_scene', '')}\n"
output += f" is_multi_az: {getattr(billing, 'is_multi_az', '')}\n"
bind_rules = getattr(vault, 'bind_rules', None)
if bind_rules:
rule_tags = getattr(bind_rules, 'tags', []) or []
output += f"\nbind_rules:\n"
if rule_tags:
output += f" tags ({len(rule_tags)}):\n"
for rt in rule_tags:
output += f" key: {getattr(rt, 'key', '')}, value: {getattr(rt, 'value', '')}\n"
else:
output += f" tags: []\n"
resources = getattr(vault, 'resources', []) or []
if resources:
output += f"\nresources ({len(resources)}):\n"
for res in resources:
output += f" id: {getattr(res, 'id', '')}\n"
output += f" name: {getattr(res, 'name', '')}\n"
output += f" type: {getattr(res, 'type', '')}\n"
output += f" protect_status: {getattr(res, 'protect_status', '')}\n"
output += f" size: {getattr(res, 'size', '')}\n"
output += f" backup_size: {getattr(res, 'backup_size', '')}\n"
output += f" backup_count: {getattr(res, 'backup_count', '')}\n"
output += f" auto_protect: {getattr(res, 'auto_protect', '')}\n"
extra_info = getattr(res, 'extra_info', None)
if extra_info:
exclude_volumes = getattr(extra_info, 'exclude_volumes', []) or []
include_volumes = getattr(extra_info, 'include_volumes', []) or []
if exclude_volumes:
output += f" extra_info.exclude_volumes: {', '.join(exclude_volumes)}\n"
if include_volumes:
output += f" extra_info.include_volumes ({len(include_volumes)}):\n"
for iv in include_volumes:
output += f" id: {getattr(iv, 'id', '')}, os_version: {getattr(iv, 'os_version', '')}\n"
tags = getattr(vault, 'tags', []) or []
if tags:
output += f"\ntags ({len(tags)}):\n"
for tag in tags:
output += f" key: {getattr(tag, 'key', '')}, value: {getattr(tag, 'value', '')}\n"
print(output)
except Exception as e:
print(f"cbr.show_vault 查询失败: {e}")
exit(1)