虚拟私有云 VPC-示例一:创建云服务器所需要的VPC和子网:操作步骤

时间:2023-11-01 16:25:15

操作步骤

  1. 创建VPC。
    1. 发送“POST https://VPC的Endpoint/v1/{project_id}/vpcs”,project_id为项目ID。
    2. 在Request Header中增加“X-Auth-Token”。
    3. 在Request Body中传入参数如下,其中cidr字段需要提前进行网络规划。
      {    "vpc": {        "name": "vpc", //虚拟私有云名称        "cidr": "192.168.0.0/16" //虚拟私有云下可用子网的范围    }}
    4. 查看请求响应结果。
      • 请求成功时,响应参数如下,id就是vpc_id。
        {    "vpc": {        "id": "b6684a27-b049-407d-90b4-c9551f2390e1",        "name": "vpc",        "cidr": "192.168.0.0/16",        "status": "CREATING",        "routes": []    }}
      • 请求异常时,错误码请参见错误码
  1. 查询VPC详情。
    1. 发送“GET https://VPC的Endpoint/v1/{project_id}/vpcs/{vpc_id}”,project_id为项目ID。
    2. 在Request Header中增加“X-Auth-Token”。
    3. 查看请求响应结果。
      • 请求成功时,响应参数如下,id就是vpc_id。
        {    "vpc": {        "id": "b6684a27-b049-407d-90b4-c9551f2390e1",        "name": "vpc",        "description": "",        "cidr": "192.168.0.0/16",        "status": "OK",        "enterprise_project_id": "0" ,        "routes": []    }}
      • 请求异常时,错误码请参见错误码
  2. 指定VPC创建子网。
    1. 发送“POST https://VPC的Endpoint/v1/{project_id}/subnets”,project_id为项目ID。
    2. 在Request Header中增加“X-Auth-Token”。
    3. 在Request Body中传入参数如下,其中dnsList参数参见华为云提供的内网DNS地址是多少?,availability_zone参数可通过地区和终端节点获取。
    4. {"subnet": {"name": "subnet","description": "","cidr": "192.168.0.0/24","gateway_ip": "192.168.0.1","dhcp_enable": true,"dnsList": ["114.xx.xx.114", "114.xx.xx.115"],"availability_zone": "aa-bb-cc","vpc_id": "b6684a27-b049-407d-90b4-c9551f2390e1"}}
    5. 查看请求响应结果。
      • 请求成功时,响应参数如下:
        {"subnet": {"id": "4779ab1c-7c1a-44b1-a02e-93dfc361b32d","name": "subnet","description": "","cidr": "192.168.0.0/24","dnsList": ["114.xx.xx.114", "1114.xx.xx.115"],"status": "UNKNOWN","vpc_id": "b6684a27-b049-407d-90b4-c9551f2390e1","gateway_ip": "192.168.0.1","dhcp_enable": true,"primary_dns": "114.xx.xx.114","secondary_dns": "114.xx.xx.115","availability_zone": "aa-bb-cc","neutron_network_id": "4779ab1c-7c1a-44b1-a02e-93dfc361b32d","neutron_subnet_id": "213cb9d-3122-2ac1-1a29-91ffc1231a12","extra_dhcp_opts": []}}
      • 请求异常时,错误码请参见错误码
  1. 查询子网详情。
    1. 发送“GET https://VPC的Endpoint/v1/{project_id}/subnets/{subnet_id}”,project_id为项目ID。
    2. 在Request Header中增加“X-Auth-Token”。
    3. 查看请求响应结果。
      {"subnet": {"id": "4779ab1c-7c1a-44b1-a02e-93dfc361b32d","name": "subnet","description": "","cidr": "192.168.20.0/24","dnsList": ["114.xx.xx.114", "114.xx.xx.115"],"status": "ACTIVE","vpc_id": "b6684a27-b049-407d-90b4-c9551f2390e1","gateway_ip": "192.168.20.1","ipv6_enable": false,"dhcp_enable": true,"primary_dns": "114.xx.xx.114","secondary_dns": "114.xx.xx.115","availability_zone": "aa-bb-cc","neutron_network_id": "4779ab1c-7c1a-44b1-a02e-93dfc361b32d","neutron_subnet_id": "213cb9d-3122-2ac1-1a29-91ffc1231a12","extra_dhcp_opts": []}}
support.huaweicloud.com/api-vpc/vpc_apieg_0002.html