Updated on 2024-04-15 GMT+08:00

Creating a Subnet

Function

This API is used to create a subnet.

URI

POST /v1/{project_id}/subnets

Table 1 describes the parameters.
Table 1 Parameter description

Name

Mandatory

Description

project_id

Yes

Specifies the project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request parameter

Name

Mandatory

Type

Description

subnet

Yes

subnet object

Specifies the subnet objects.

Table 3 subnet objects

Name

Mandatory

Type

Description

name

Yes

String

  • Specifies the subnet name.
  • The value can contain 1 to 64 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).

description

No

String

  • Provides supplementary information about the subnet.
  • The value can contain no more than 255 characters and cannot contain angle brackets (< or >).

cidr

Yes

String

  • Specifies the subnet CIDR block.
  • The value must be within the VPC CIDR block.
  • The value must be in CIDR format. The subnet mask cannot be greater than 28.

gateway_ip

Yes

String

  • Specifies the gateway of the subnet.
  • The value must be an IP address in the subnet.
  • The value must be a valid IP address.

ipv6_enable

No

Boolean

  • Specifies whether IPv6 is enabled.
  • The value can be true (enabled) or false (disabled).
  • If this parameter is left blank, the system automatically sets it to false by default.

dhcp_enable

No

Boolean

  • Specifies whether DHCP is enabled for the subnet.
  • The value can be true (enabled) or false (disabled).
  • If this parameter is left blank, the value is set to true by default. If this parameter is set to false, newly created ECSs cannot obtain IP addresses, and usernames and passwords cannot be injected using Cloud-init.

primary_dns

No

String

  • Specifies the primary IP address of DNS server on the subnet.
  • The value must be an IP address. If the value is not specified, the default value will be left blank.

secondary_dns

No

String

  • Specifies the standby IP address of DNS server on the subnet.
  • The value must be an IP address. If the value is not specified, the default value will be left blank.

    If only secondary_dns is specified and primary_dns is not specified, primary_dns will automatically use the value of secondary_dns.

    If there is only one DNS server address, only primary_dns is displayed.

dnsList

No

Array of strings

  • Specifies the DNS server address list of a subnet. This field is required if you need to use more than two DNS servers.
  • This parameter value is the superset of both DNS server address 1 and DNS server address 2. If the value is not specified, the default value will be left blank.

availability_zone

No

String

  • Specifies the AZ to which the subnet belongs, which can be obtained from endpoints. For details, see Endpoints.
  • The value must be an existing AZ in the system. If the value is not specified, the default value will be left blank.

vpc_id

Yes

String

Specifies the ID of the VPC to which the subnet belongs.

extra_dhcp_opts

No

Array of extra_dhcp_opt objects

Specifies the NTP server address configured for the subnet. For details, see Table 4.

Table 4 extra_dhcp_opt object

Name

Mandatory

Type

Description

opt_value

No

String

  • Specifies the NTP server address configured for the subnet.
  • Constraints:

    The option ntp for opt_name indicates the NTP server configured for the subnet. Currently, only IPv4 addresses are supported. A maximum of four IP addresses can be configured, and each address must be unique. Multiple IP addresses must be separated using commas (,). The option null for opt_name indicates that no NTP server is configured for the subnet. The parameter value cannot be an empty string.

opt_name

Yes

String

  • Specifies the NTP server address configured for the subnet.
  • Currently, the value can only be set to ntp.

Example Request

  • Create a subnet with name set to subnet, CIDR block set to 192.168.20.0/24, and gateway IP address set to 192.168.20.1 in the VPC with ID of 3ec3b33f-ac1c-4630-ad1c-7dba1ed79d85.
    POST https://{Endpoint}/v1/{project_id}/subnets
    
    {
        "subnet": {
            "name": "subnet",
            "description": "",
            "cidr": "192.168.20.0/24",
            "gateway_ip": "192.168.20.1",
            "ipv6_enable": true,
            "dhcp_enable": true,
            "primary_dns": "114.xx.xx.114",
            "secondary_dns": "114.xx.xx.115",
            "dnsList": [
                "114.xx.xx.114",
                "114.xx.xx.115"
            ],
            "vpc_id": "3ec3b33f-ac1c-4630-ad1c-7dba1ed79d85"
        }
    }

Response Parameters

Table 5 Response parameter

Name

Type

Description

subnet

subnet object

Specifies the subnet objects.

Table 6 subnet objects

Name

Type

Description

id

String

Specifies the resource identifier in the form of UUID.

name

String

  • Specifies the subnet name.
  • The value can contain 1 to 64 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).

description

String

  • Provides supplementary information about the subnet.
  • The value can contain no more than 255 characters and cannot contain angle brackets (< or >).

cidr

String

  • Specifies the subnet CIDR block.
  • The value must be within the VPC CIDR block.
  • The value must be in CIDR format. The subnet mask cannot be greater than 28.

gateway_ip

String

  • Specifies the gateway of the subnet.
  • The value must be an IP address in the subnet.
  • The value must be a valid IP address.

ipv6_enable

Boolean

Specifies whether IPv6 is enabled.

cidr_v6

String

Specifies the IPv6 subnet CIDR block. If the subnet is an IPv4 subnet, this parameter is not returned.

gateway_ip_v6

String

Specifies the IPv6 subnet gateway. If the subnet is an IPv4 subnet, this parameter is not returned.

dhcp_enable

Boolean

Specifies whether DHCP is enabled for the subnet.

primary_dns

String

  • Specifies the primary IP address of DNS server on the subnet.
  • The value must be an IP address. If the value is not specified, the default value will be left blank.

secondary_dns

String

  • Specifies the standby IP address of DNS server on the subnet.
  • The value must be an IP address. If the value is not specified, the default value will be left blank.

    If only secondary_dns is specified and primary_dns is not specified, primary_dns will automatically use the value of secondary_dns.

    If there is only one DNS server address, only primary_dns is displayed.

dnsList

Array of strings

  • Specifies the DNS server address list of a subnet. This field is required if you need to use more than two DNS servers.
  • This parameter value is the superset of both DNS server address 1 and DNS server address 2. If the value is not specified, the default value will be left blank.

availability_zone

String

  • Specifies the AZ to which the subnet belongs, which can be obtained from endpoints. For details, see Endpoints.
  • The value must be an existing AZ in the system. If the value is not specified, the default value will be left blank.

vpc_id

String

Specifies the ID of the VPC to which the subnet belongs.

status

String

  • Specifies the status of the subnet.
  • The value can be ACTIVE, UNKNOWN, or ERROR.
    • ACTIVE: indicates that the subnet has been associated with a VPC.
    • UNKNOWN: indicates that the subnet has not been associated with a VPC.
    • ERROR: indicates that the subnet is abnormal.
  • The system creates a subnet and then associates the subnet with a VPC in the threads.

    In the concurrent scenario, if the CIDR block of the created subnet is the same as that of an existing subnet, the created subnet fails to associate with a VPC after underlying system verification. As a result, the subnet creation fails.

  • The value of status is UNKNOWN before the subnet is associated with a VPC. After the subnet is associated with a VPC in the threads, the status of the subnet is ACTIVE.

neutron_network_id

String

Specifies the ID of the corresponding network (OpenStack Neutron API).

neutron_subnet_id

String

Specifies the ID of the corresponding subnet (OpenStack Neutron API).

neutron_subnet_id_v6

String

Specifies the ID of the IPv6 subnet (OpenStack Neutron API). If the subnet is an IPv4 subnet, this parameter is not returned.

extra_dhcp_opts

Array of extra_dhcp_opt objects

Specifies the NTP server address configured for the subnet. For details, see Table 7.

Table 7 extra_dhcp_opt object

Name

Mandatory

Type

Description

opt_value

No

String

  • Specifies the NTP server address configured for the subnet.
  • Constraints:

    The option ntp for opt_name indicates the NTP server configured for the subnet. Currently, only IPv4 addresses are supported. A maximum of four IP addresses can be configured, and each address must be unique. Multiple IP addresses must be separated using commas (,). The option null for opt_name indicates that no NTP server is configured for the subnet. The parameter value cannot be an empty string.

opt_name

Yes

String

  • Specifies the NTP server address configured for the subnet.
  • Currently, the value can only be set to ntp.

Example Response

{
    "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": "UNKNOWN",
        "vpc_id": "3ec3b33f-ac1c-4630-ad1c-7dba1ed79d85",
        "gateway_ip": "192.168.20.1",
        "ipv6_enable": true, 
        "cidr_v6": "2001:db8:a583::/64",
        "gateway_ip_v6": "2001:db8:a583::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"
        "neutron_subnet_id_v6": "e0fa7de1-a6e2-44c9-b052-b9d8cebe93c4",  
    }
}

Status Code

See Status Codes.

Error Code

See Error Codes.