Loading...
Loading...
Use when managing Alibaba Cloud Virtual Private Cloud (VPC) via OpenAPI/SDK, including listing or creating VPCs and VSwitches, querying available zones, deleting VPC resources, managing route tables, and troubleshooting VPC network configurations.
npx skill4agent add cinience/alicloud-skills aliyun-vpc-managemkdir -p output/aliyun-vpc-manage
for f in skills/network/vpc/aliyun-vpc-manage/scripts/*.py; do
python3 -m py_compile "$f"
done
echo "py_compile_ok" > output/aliyun-vpc-manage/validate.txtoutput/aliyun-vpc-manage/validate.txtoutput/aliyun-vpc-manage/pip install alibabacloud_vpc20160428 alibabacloud_tea_openapi alibabacloud_credentialsDescribeVpcsDescribeVSwitchesPageNumberPageSizeDescribeVpcsRegionIdCreateVpcVpcIdPendingDescribeVpcsAvailableCreateVSwitchAvailableZoneIdDeleteVpcDeleteVSwitchreferences/api_overview.mdscripts/output/aliyun-vpc-manage/python3 -m venv .venv
. .venv/bin/activate
pip install alibabacloud_vpc20160428 alibabacloud_tea_openapi alibabacloud_credentialsfrom alibabacloud_vpc20160428.client import Client as Vpc20160428Client
from alibabacloud_vpc20160428 import models as vpc_models
from alibabacloud_tea_openapi import models as open_api_models
def create_client(region_id: str) -> Vpc20160428Client:
config = open_api_models.Config(
region_id=region_id,
endpoint=f"vpc.{region_id}.aliyuncs.com",
)
return Vpc20160428Client(config)
def list_vpcs(region_id: str):
client = create_client(region_id)
resp = client.describe_vpcs(vpc_models.DescribeVpcsRequest(
region_id=region_id,
page_number=1,
page_size=50,
))
for v in resp.body.vpcs.vpc:
print(v.vpc_id, v.vpc_name, v.cidr_block, v.status)
if __name__ == "__main__":
list_vpcs("cn-hangzhou")scripts/list_vpcs.pyscripts/list_vswitches.pyscripts/create_vpc.pyscripts/create_vswitch.pyscripts/delete_vpc.pyscripts/delete_vswitch.pyscripts/describe_zones.py| 地域 | 推荐 CIDR |
|---|---|
| cn-hangzhou | 10.1.0.0/16 |
| cn-shanghai | 10.2.0.0/16 |
| ap-southeast-1 | 10.3.0.0/16 |
| cn-beijing | 10.4.0.0/16 |
| 更多地域 | 10.5~254.0.0/16 |
10.0.0.0/810.xscripts/describe_zones.py10.x.0~9.0/24 → 应用层(Web/API 服务器)
10.x.10~19.0/24 → 数据层(RDS、Redis、MongoDB)
10.x.20~29.0/24 → 中间件(MQ、ES、Nacos)
10.x.30~39.0/24 → 管理层(跳板机、运维工具)vsw-{region简写}-{可用区}-{用途}vsw-sg-a-appvsw-hz-h-dbvsw-sh-e-middleware10.0.0.0/810.x| 问题 | 原因 | 解决方案 |
|---|---|---|
| CEN 挂载失败,提示 CIDR 冲突 | 两个 VPC 使用了重叠的 CIDR | 新建 VPC 使用不重叠的 /16 网段 |
| DeleteVpc 失败 | VPC 下仍有 VSwitch/安全组/NAT 等资源 | 先删除所有子资源,再删 VPC |
| DeleteVSwitch 失败 | VSwitch 下仍有 ECS/RDS 等实例 | 先释放或迁移实例 |
| 创建 VSwitch 报 ZoneId 无效 | 该可用区不支持或已售罄 | 用 describe_zones.py 查询有效可用区 |
| 默认 VPC 用于生产 | 默认 VPC 网段不可控,且无法与其他 VPC 合理互联 | 生产环境始终新建 VPC,规划好 CIDR |
CreateVpcDeleteVpcModifyVpcAttributeDescribeVpcsDescribeVpcAttributeCreateVSwitchDeleteVSwitchModifyVSwitchAttributeDescribeVSwitchesDescribeVSwitchAttributesCreateRouteTableDeleteRouteTableDescribeRouteTablesCreateRouteEntryDeleteRouteEntryCreateNatGatewayDeleteNatGatewayDescribeNatGatewaysAllocateEipAddressAssociateEipAddressUnassociateEipAddressReleaseEipAddressDescribeEipAddressesTagResourcesUntagResourcesListTagResourcesDescribeVpcsVpcIdVpcNameIsDefaultResourceGroupIdDescribeVSwitchesVpcIdVSwitchIdZoneIdVSwitchNameIsDefaultDescribeZonesALIBABACLOUD_ACCESS_KEY_IDALIBABACLOUD_ACCESS_KEY_SECRETALIBABACLOUD_REGION_IDALIBABACLOUD_REGION_ID~/.alibabacloud/credentialsexport ALIBABACLOUD_ACCESS_KEY_ID="your-ak"
export ALIBABACLOUD_ACCESS_KEY_SECRET="your-sk"
export ALIBABACLOUD_REGION_ID="cn-hangzhou"export ALIBABA_CLOUD_ACCESS_KEY_ID="your-ak"
export ALIBABA_CLOUD_ACCESS_KEY_SECRET="your-sk"export ALICLOUD_ACCESS_KEY_ID="your-ak"
export ALICLOUD_ACCESS_KEY_SECRET="your-sk"~/.alibabacloud/credentials[default]
type = access_key
access_key_id = your-ak
access_key_secret = your-skVpc2016-04-28output/aliyun-vpc-manage/references/api_overview.mdreferences/sources.md