Create Subnet

Verb URI Description
POST /subnets Creates a subnet on the specified network.

Normal Response Code: Created (201)

Error Response Codes: Bad Request (400), Unauthorized (401), Forbidden (403), Not Found (404), Conflict (409)

This operation creates a new subnet on the specified network. The network ID, network_id, is required. You must also specify the cidr attribute for the subnet, in the form:

network_address/prefix

The remaining attributes are optional.

By default, OpenStack Networking creates IP v4 subnets. To create an IP v6 subnet, you must specify the value 6 for the ip_version attribute in the request body. OpenStack Networking does not try to derive the correct IP version from the provided CIDR. If the parameter for the gateway address, gateway_ip, is not specified, OpenStack Networking allocates an address from the cidr for the gateway for the subnet.

To specify a subnet without a gateway, specify the value null for the gateway_ip attribute in the request body. If allocation pools attribute, allocation_pools, is not specified, OpenStack Networking automatically allocates pools for covering all IP addresses in the CIDR, excluding the address reserved for the subnet gateway. Otherwise, you can explicitly specify allocation pools as shown in the following example.

When allocation_pools and gateway_ip are both specified, it is up to the user ensuring the gateway ip does not overlap with the specified allocation pools; otherwise a 409 Conflict error will be returned.

 

Example 4.19. Create Subnet: JSON Request

POST /v2.0/subnets
Content-Type: application/json
Accept: application/json
{
   "subnet":{
      "network_id":"ed2e3c10-2e43-4297-9006-2863a2d1abbc",
      "ip_version":4,
      "cidr":"10.0.3.0/24",
      "allocation_pools":[
         {
            "start":"10.0.3.20",
            "end":"10.0.3.150"
         }
      ]
   }
}

 

Example 4.20. Create Subnet: JSON Response

status: 201, 
content-length: 306,
content-type: application/json

{
  "subnet": {
    "name": "",
    "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
    "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
    "allocation_pools": [{"start": "10.0.3.20", "end": "10.0.3.150"}],
    "gateway_ip": "10.0.3.1",
    "ip_version": 4,
    "cidr": "10.0.3.0/24",
    "id": "9436e561-47bf-436a-b1f1-fe23a926e031",
    "enable_dhcp": true}
}

Log a bug against this page


loading table of contents...