Method | URI | Description |
---|---|---|
POST | /v2.0/subnets | Creates a subnet on a specified network. |
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 to ensure that the gateway IP does not
overlap with the specified allocation pools; otherwise
a 409 Conflict error occurs.
Normal response codes: 201
Error response codes: badRequest (400), unauthorized (401), forbidden (403), itemNotFound (404), conflict (409)
Example 3.19. Create subnet: JSON request
{ "subnet":{ "subnet":{ "network_id":"d32019d3-bc6e-4319-9c1d-6722fc136a22", "ip_version":4, "cidr":"192.168.199.0/24" } } }
Example 3.20. Create subnet: XML request
<?xml version="1.0" encoding="UTF-8"?> <subnet> <name>test_subnet_1</name> <network_id>d32019d3-bc6e-4319-9c1d-6722fc136a22</network_id> <cidr>192.0.0.0/8</cidr> <ip_version>4</ip_version> </subnet>
This operation does not require a request body.
Example 3.21. Create subnet: JSON response
{ "subnet":{ "name":"", "enable_dhcp":true, "network_id":"d32019d3-bc6e-4319-9c1d-6722fc136a22", "tenant_id":"4fd44f30292945e481c7b8a0c8908869", "dns_nameservers":[ ], "allocation_pools":[ { "start":"192.168.199.2", "end":"192.168.199.254" } ], "host_routes":[ ], "ip_version":4, "gateway_ip":"192.168.199.1", "cidr":"192.168.199.0/24", "id":"3b80198d-4f7b-4f77-9ef5-774d54e17126" } }
Example 3.22. Create subnet: XML response
<?xml version='1.0' encoding='UTF-8'?> <subnet xmlns="http://openstack.org/quantum/api/v2.0" xmlns:quantum="http://openstack.org/quantum/api/v2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <name>test_subnet_1</name> <enable_dhcp quantum:type="bool">True</enable_dhcp> <network_id>d32019d3-bc6e-4319-9c1d-6722fc136a22</network_id> <tenant_id>4fd44f30292945e481c7b8a0c8908869</tenant_id> <dns_nameservers quantum:type="list"/> <allocation_pools> <allocation_pool> <start>192.0.0.2</start> <end>192.255.255.254</end> </allocation_pool> </allocation_pools> <host_routes quantum:type="list"/> <ip_version quantum:type="int">4</ip_version> <gateway_ip>192.0.0.1</gateway_ip> <cidr>192.0.0.0/8</cidr> <id>54d6f61d-db07-451c-9ab3-b9609b6b6f0b</id> </subnet>
This operation does not return a response body.