Create Subnets

Last updated: 2018-05-28 19:36:32

PDF

1. API Description

This API (CreateSubnet) is used to create subnets.
Domain for API request:vpc.api.qcloud.com

1) You must have created the VPC before you can create subnets.
2) Once a subnet is created, you can no longer change its network segment. The subnet network segment must lie within the VPC network segment. They can be the same, in which case the VPC will only have one subnet. It is recommended to keep subnet network segment within the range of VPC network segment in order to reserve network segment for other subnets.
3) The subnet mask of the smallest possible network segment you can create is 28 (16 IP addresses), while the subnet mask of the largest possible network segment is 16 (65,536 IP addresses).
4) Network segments of different subnets must not overlap with each other within the same VPC.
5) A subnet will be automatically associated to the default routing table once it is created.

2. Input Parameters

The following request parameter list only provides API request parameters. Common request parameters need to be added when the API is called. For more information, refer to Common Request Parameters. The Action field for this API is CreateSubnet.

Parameter Name Required Type Description
vpcId Yes String VPC ID of the subnet, which can be vpcId or unVpcId. unVpcId is recommended. Can be queried via API DescribeVpcEx.
subnetSet.n Yes Array Subnet information array. You can create subnets as you create the VPC. Optional.
subnetSet.n.subnetName Yes String Subnet name. You can specify any name you like, but its length should be limited to 60 characters.
subnetSet.n.cidrBlock Yes String Subnet network segment. It must lie within the range of the VPC network segment. Subnet network segments must not overlap with each other within the same VPC.
subnetSet.n.zoneId Yes Int ID of the availability zone in which the subnet resides. You may set up disaster tolerance across availability zones by choosing different availability zones for different subnets. Refer to VPC Availability Zone Instruction for available values.

3. Output Parameters

Parameter Name Type Description
code Int Common error code; 0: Succeeded; other values: Failed. For more information, please refer to Common Error Codes on the Error Code page.
message String Module error message description depending on API.
subnetSet.n Array Subnet information, which is returned when a subnet is added.
subnetSet.n.subnetId String Subnet ID assigned by the system. For example: subnetId_GZ_23.
subnetSet.n.unSubnetId String Unified subnet ID assigned by the system, upgraded from subnet ID. For example: subnet-5gu2jxf4. The system supports both IDs for compatibility purpose.
subnetSet.n.subnetName String Subnet name.
subnetSet.n.cidrBlock String Subnet network segment, for example: 192.168.0.0/25.
subnetSet.n.routeTableId String ID of the default routing table that is bound to the subnet. For example: gz_rtb_8751.
subnetSet.n.zoneId String ID of the availability zone in which the subnet resides. For example: 200001.

4. Error Code Table

The following error code list only provides the business logic error codes for this API. For additional common error codes, refer to VPC Error Codes.

Error Code Description
InvalidVpc.NotFound Invalid VPC. VPC resource does not exist. Please verify that the resource information you entered is correct. You can query the VPC via the API DescribeVpcEx.
InvalidSubnetName Invalid subnet name. You can specify any name you like, but its length should be limited to 60 characters.
InvalidSubnetCidr Subnet CIDR is invalid or does not lie within the range of the VPC network segment. Subnet CIDR value range: 10.0.0.0/16, 172.16.0.0/16, 192.168.0.0/16 and their subnets.
InvalidSubnet.Conflict Subnet network segment is in conflict with other segments within the VPC.
SubnetLimitExceeded The limit of requested subnet resources for the specific region has been reached. Please contact customer service for more resources. For more information on VPC resource restrictions, see VPC Usage Restrictions.
InvalidZone.NotFound Invalid availability zone ID. The availability zone you have entered does not exist or does not support VPC. Refer to VPC Availability Zone Instruction for more information on availability zones.

5. Example

Input

  https://vpc.api.qcloud.com/v2/index.php?Action=CreateSubnet
    &<Common request parameters>
  &vpcId=vpc-kd7d06of
  &subnetSet.0.subnetName=tttt
  &subnetSet.0.cidrBlock=10.0.200.0/24
  &subnetSet.0.zoneId=800001

Output

{
    "code": 0,
    "message": "",
    "subnetSet": [
        {
            "subnetId": "gz_subnet_18748",
            "unSubnetId": "subnet-3lzrkspo",
            "routeTableId": "gz_rtb_359",
            "unRouteTableId": null,
            "subnetName": "tttt",
            "cidrBlock": "10.0.200.0\/24",
            "zoneId": 800001
        }
    ]
}