Creating a Subnet¶
Function¶
This API is used to create a subnet.
Notes and Constraints¶
IPv6 subnets can be created only when IPv4 subnets have been created on the network.
URI¶
POST /v2.0/subnets
Request Parameters¶
Parameter | Type | Mandatory | Description |
---|---|---|---|
subnet | subnet object | Yes | Specifies the subnet. For details, see Table 2. |
Attribute | Mandatory | Type | Description |
---|---|---|---|
name | No | String | Specifies the subnet name. |
ip_version | No | Integer | Specifies the IP address version. The value can be 4 (IPv4) or 6 (IPv6). |
ipv6_address_mode | No | String | Specifies the IPv6 addressing mode. Only dhcpv6-stateful is supported. |
ipv6_ra_mode | No | String | Specifies the IPv6 route broadcast mode. Only dhcpv6-stateful is supported. |
network_id | Yes | String | Specifies the ID of the network to which the subnet belongs. |
cidr | Yes | String | Specifies the CIDR format. Only the IPv4 addresses in the 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 ranges are supported. The subnet mask cannot be greater than 28. This parameter cannot be set if the value of ip_version is 6. |
gateway_ip | No | String | The gateway IP address cannot conflict with IP addresses configured for allocation_pools. This attribute cannot be modified. |
allocation_pools | No | Array of allocation_pool objects | Specifies the available IP address pool. For details, see Table 3. Example: [ { "start": "10.0.0.2", "end": "10.0.0.251"} ] The last three and the first IP addresses in each subnet are the ones reserved by the system. For example, in subnet 192.168.1.0/24, IP addresses 192.168.1.0, 192.168.1.253, 192.168.1.254, and 192.168.1.255 are reserved by the system. [{"start": "2001:db8:a583:9::2", "end": "2001:db8:a583:9:ffff:ffff:ffff:fffc"}] In IPv6 subnet 2001:db8:a583:9::/64, IP addresses 2001:db8:a583:9::1, 2001:db8:a583:9:ffff:ffff:ffff:fffd, 2001:db8:a583:9:ffff:ffff:ffff:fffe, and 2001:db8:a583:9:ffff:ffff:ffff:ffff are reserved by the system. By default, the IP addresses reserved by the system are not in the IP address pool specified by allocation_pool. When updating an IP address pool, the allocation_pool value can contain neither gateway nor broadcast IP addresses. |
dns_nameservers | No | Array of strings | Specifies the DNS server address. Instructions: Example: "dns_nameservers": ["8.xx.xx.8","8.xx.xx.4"] A maximum of five DNS server addresses are supported. |
host_routes | No | Array of host_route objects | Specifies the static VM routes. For details, see Table 4. Static routes are not supported, and entered information will be ignored. |
enable_dhcp | No | Boolean | Specifies whether to enable the DHCP function. Value false indicates that the DHCP function is not enabled. The value can only be true. |
use_default_subnetpool | No | Boolean | Specifies whether to use the default subnet pool. The value can be set to true only when IPv6 is used. |
Parameter | Mandatory | Type | Description |
---|---|---|---|
start | No | String | Specifies the start IP address of a network pool. |
end | No | String | Specifies the end IP address of a network pool. |
Parameter | Mandatory | Type | Description |
---|---|---|---|
destination | No | String | Specifies the destination subnet of a route. |
nexthop | No | String | Specifies the next-hop IP address of a route. |
Example Request¶
Create an IPv4 subnet named subnet-test, set its network ID to 0133cd73-34d4-4d4c-bf1f-e65b24603206, and CIDR block to 172.16.2.0/24.
POST https://{Endpoint}/v2.0/subnets
{
"subnet": {
"name": "subnet-test",
"network_id": "0133cd73-34d4-4d4c-bf1f-e65b24603206",
"cidr": "172.16.2.0/24",
"enable_dhcp": true
}
}
Create an IPv6 subnet named subnet-ipv6-test and with network ID of 0133cd73-34d4-4d4c-bf1f-e65b24603206.
POST https://{Endpoint}/v2.0/subnets
{
"subnet": {
"name": "subnet-ipv6-test",
"network_id": "0133cd73-34d4-4d4c-bf1f-e65b24603206",
"ip_version": 6,
"enable_dhcp": true,
"ipv6_address_mode": "dhcpv6-stateful",
"ipv6_ra_mode": "dhcpv6-stateful",
"use_default_subnetpool": true
}
}
Response Parameters¶
Attribute | Type | Description |
---|---|---|
id | String | Specifies the subnet ID. This parameter is not mandatory when you query subnets. |
name | String | Specifies the subnet name. |
ip_version | Integer | Specifies the IP address version. The value can be 4 (IPv4) or 6 (IPv6). |
ipv6_address_mode | String | Specifies the IPv6 addressing mode. Only dhcpv6-stateful is supported. |
ipv6_ra_mode | String | Specifies the IPv6 route broadcast mode. Only dhcpv6-stateful is supported. |
network_id | String | Specifies the ID of the network to which the subnet belongs. |
cidr | String | Specifies the CIDR format. Only the IPv4 addresses in the 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 ranges are supported. The subnet mask cannot be greater than 28. This parameter cannot be set if the value of ip_version is 6. |
gateway_ip | String | The gateway IP address cannot conflict with IP addresses configured for allocation_pools. This attribute cannot be modified. |
allocation_pools | Array of allocation_pool objects | Specifies the available IP address pool. For details, see the allocation_pool objects. Example: [ { "start": "10.0.0.2", "end": "10.0.0.251"} ] The last three and the first IP addresses in each subnet are the ones reserved by the system. For example, in subnet 192.168.1.0/24, IP addresses 192.168.1.0, 192.168.1.253, 192.168.1.254, and 192.168.1.255 are reserved by the system. By default, the IP addresses reserved by the system are not in the IP address pool specified by allocation_pool. [{"start": "2001:db8:a583:9::2", "end": "2001:db8:a583:9:ffff:ffff:ffff:fffc"}] In IPv6 subnet 2001:db8:a583:9::/64, IP addresses 2001:db8:a583:9::1, 2001:db8:a583:9:ffff:ffff:ffff:fffd, 2001:db8:a583:9:ffff:ffff:ffff:fffe, and 2001:db8:a583:9:ffff:ffff:ffff:ffff are reserved by the system. When updating an IP address pool, the allocation_pool value can contain neither gateway nor broadcast IP addresses. |
dns_nameservers | Array of strings | Specifies the DNS server address. Example: "dns_nameservers": ["8.xx.xx.8","8.xx.xx.4"] |
host_routes | Array of host_route objects | Specifies the static VM routes. For details, see Table 8. Static routes are not supported, and entered information will be ignored. |
tenant_id | String | Specifies the project ID. |
enable_dhcp | Boolean | Specifies whether to enable the DHCP function. Value false indicates that the DHCP function is not enabled. The value can only be true. |
subnetpool_id | String | Specifies the subnet pool ID. Currently, only IPv6 is supported. |
project_id | String | Specifies the project ID. |
created_at | String | Specifies the time (UTC) when the subnet is created. Format: yyyy-MM-ddTHH:mm:ss |
updated_at | String | Specifies the time (UTC) when the subnet is updated. Format: yyyy-MM-ddTHH:mm:ss |
Parameter | Type | Remarks |
---|---|---|
start | String | Specifies the start IP address of a network pool. |
end | String | Specifies the end IP address of a network pool. |
Parameter | Type | Remarks |
---|---|---|
destination | String | Specifies the destination subnet of a route. |
nexthop | String | Specifies the next-hop IP address of a route. |
Example Response¶
{
"subnet": {
"name": "subnet-test",
"cidr": "172.16.2.0/24",
"id": "98bac90c-0ba7-4a63-8995-097da9bead1c",
"enable_dhcp": true,
"network_id": "0133cd73-34d4-4d4c-bf1f-e65b24603206",
"tenant_id": "bbfe8c41dd034a07bebd592bf03b4b0c",
"project_id": "bbfe8c41dd034a07bebd592bf03b4b0c",
"dns_nameservers": [],
"allocation_pools": [
{
"start": "172.16.2.2",
"end": "172.16.2.251"
}
],
"host_routes": [],
"ip_version": 4,
"gateway_ip": "172.16.2.1",
"created_at": "2018-09-20T02:02:16",
"updated_at": "2018-09-20T02:02:16"
}
}
{
"subnet": {
"id": "011fc878-5521-4654-a1ad-f5b0b58203ac",
"name": "subnet-ipv6-test",
"tenant_id": "bbfe8c41dd034a07bebd592bf03b4b0c",
"network_id": "0133cd73-34d4-4d4c-bf1f-e65b24603206",
"ip_version": 6,
"cidr": "2001:db8:a583:a0::/64",
"subnetpool_id": "cb03d100-8687-4c0a-9441-ea568dcae47d",
"allocation_pools": [{
"start": "2001:db8:a583:a0::2",
"end": "2001:db8:a583:a0:ffff:ffff:ffff:fffc"
}],
"gateway_ip": "2001:db8:a583:a0::1",
"enable_dhcp": true,
"ipv6_ra_mode": "dhcpv6-stateful",
"ipv6_address_mode": "dhcpv6-stateful",
"description": "",
"dns_nameservers": [],
"host_routes": [],
"project_id": "bbfe8c41dd034a07bebd592bf03b4b0c",
"created_at": "2021-07-01T07:59:28",
"updated_at": "2021-07-01T07:59:28"
}
}
Status Code¶
See Status Codes.
Error Code¶
See Error Codes.