Jump to: navigation, search

Difference between revisions of "Neutron/APIv2-specification"

m (High-level flow)
 
(39 intermediate revisions by 11 users not shown)
Line 1: Line 1:
__NOTOC__
+
 
= Quantum v2 API =
+
= Neutron v2 API =
 +
This page is a draft spec and may not reflect the actual implementation.
 +
 
 +
Refer to http://developer.openstack.org/api-ref-networking-v2.html for the latest.
 +
 
 +
__TOC__
  
 
== Overview ==
 
== Overview ==
 +
Neutron is a project to provide virtual networking services between devices managed by the [[OpenStack]] compute service.  This document presents and discusses version 2.0 of the Neutron API. For more information on the Neutron project, and additional documentation, please visit http://wiki.openstack.org/Neutron, and docs.openstack.org. We welcome feedback, comments, and bug reports at https://bugs.launchpad.net/neutron.
  
Quantum is a project to provide virtual networking services between devices managed by the [[OpenStack]] compute service.
+
The v2.0 API represents a combination of the [http://docs.openstack.org/api/openstack-network/1.0/content/ Quantum v1.1 API] with some of the most essential IPAM capabilities from the [http://melange.readthedocs.org/en/latest/apidoc.html Melange API] .  These IPAM capabilities focus on being able to associate IP address blocks and other network configuration required by a network device (e.g., default gateway, dns-servers) with a Neutron Network, and then being able to allocate an IP address out of such a block and associate it with a device that is attached to the network via a Neutron Port.
This document presents and discusses version 2.0 of the Quantum API. For more information on the Quantum project, and additional documentation, please visit http://wiki.openstack.org/Quantum, and docs.openstack.org.
 
We welcome feedback, comments, and bug reports at bugs.launchpad.net/Quantum.
 
 
 
The v2.0 API represents a combination of the [http://docs.openstack.org/api/openstack-network/1.0/content/ Quantum v1.1 API] with some of the most essential IPAM capabilities from the [http://melange.readthedocs.org/en/latest/apidoc.html Melange API] .  These IPAM capabilities focus on being able to associate IP address blocks and other network configuration required by a network device (e.g., default gateway, dns-servers) with a Quantum Network, and then being able to allocate an IP address out of such a block and associate it with a device that is attached to the network via a Quantum Port.
 
  
The v2.0 API does this by introducing a new enity, called a Subnet.  Subnets can represent either a v4 or v6 address block, and each Quantum Network commonly has one or more subnets.  When a port is created on the network, by default it will be allocated an available fixed IP address out of one the designated subnets for each IP version.  When the Port is destroyed, the allocated addresses return to the pool of available IPs on the subnet. Users of the Quantum API can either choose a specific IP address from the block, or let Quantum choose the first available IP address.
+
The v2.0 API does this by introducing a new entity, called a Subnet.  Subnets can represent the binding of either a IPv4 or IPv6 address block to a previously created Quantum network, and each Neutron Network commonly has one or more subnets.  When a port is created on the network, by default it will be allocated an available fixed IP address out of one the designated subnets for each IP version.  When the Port is destroyed, the allocated addresses return to the pool of available IPs on the subnet. Users of the Neutron API can either choose a specific IP address from the block, or let Neutron choose the first available IP address.
  
''Please note that version 1.x of the Quantum API has been removed from the source code tree. In order to use v1.x API, an earlier release of Quantum should be installed.''
+
''Please note that version 1.x of the Neutron API has been removed from the source code tree. In order to use v1.x API, an earlier release of Neutron should be installed.''
  
 
=== High-level flow ===
 
=== High-level flow ===
 
 
* Tenant creates a network (e.g., "net1")
 
* Tenant creates a network (e.g., "net1")
* Tenant associates a subnet with that network (e.g., "10.0.0.0/24") (may be combined with step above)
+
* Tenant creates a subnet (e.g., "10.0.0.0/24"), which implicitly associates the address space with that network. This association creates a binding of the address space to the previously created network. While it is common to say, that a subnet is represented by an IPv4 or IPv6 address range, the address range alone is not a subnet. Rather it is the binding of the address space to the network, which creates the subnet.
* Tenant boots a VM, specifying a single NIC connected to "net1".
+
* Tenant boots a VM, specifying a single NIC connected to "net1" (e.g.: nova boot --image <image_name> --nic net-id=<id_of_net1> <server_name>)
* Nova contacts Quantum and creates a port1 on net1. port1 is assigned IP (e.g., 10.0.0.2).
+
* Nova contacts Neutron and creates a port1 on net1.
 +
* Neutron assigns an IP to port1 is assigned IP. (The IP is chosen by Neutron)
 
* Tenant destroys VM.
 
* Tenant destroys VM.
* Nova contacts Quantum and destroys port1. IP (e.g., 10.0.0.2) is returned to pool.
+
* Nova contacts Neutron and destroys port1. Allocated IP is returned to the pool of available IP address.
  
The API supports many more options and some alternative flows (e.g., user requesting an IP), but the above flow is a good place to start.
+
=== The Plugin ===
 +
While the Neutron API represents the interface of the virtual network service to users and other services, these network services are implemented by a component called "Plugin". Plugins may adopt different techniques and technologies for providing isolated virtual networks to tenant, as well as providing other services such as IP address management. Users should not be concerned about the particular plugin employed as far as the API discussed in this document is concerned, as every plugin will implement all the operations included in the Neutron v2 API.
  
More advanced capabilities, including Security Groups, L3-forwarding between different Quantum Networks, Floating IPs, etc. will be implemented as API extensions in Folsom.
+
However, some plugins might expose additional capabilities through API extensions, discussed later in this document. For more information about the extensions exposed by a particular plugin, please refer to the plugin documentation.
  
=== The Plugin ===
+
== Concepts ==
 +
The Neutron v2 API manages three kind of entities:
  
A brief discussion of what a plugin is. Maybe just provide list of available plugins.
+
* '''Network''', representing isolated virtual Layer-2 domains; a network can also be regarded as a virtual (or logical) switch;
 +
* '''Subnet''', representing IPv4 or IPv6 address blocks  from which IPs to be assigned to VMs on a given network are selected.
 +
* '''Port''', representing virtual (or logical) switch ports on a given network.
  
== Concepts ==
+
All entities, discussed in detail in the rest of this chapter, support the basic CRUD operations with POST/GET/PUT/DELETE verbs, and have an auto-generated unique identifier.
All entities support the basic CRUD operations with POST/GET/PUT/DELETE operations on an entity + UUID URL (e.g., /v2.0/networks/98bd8391-199f-4440-824d-8659e4906786) as well as search operations with filtering using a GET on the base entity URL (e.g., /v2.0/networks ).
 
  
 
=== Network ===
 
=== Network ===
/v2.0/networks
+
A network is a virtual isolated layer-2 broadcast domain which is typically reserved to the tenant who created it, unless the network has been explicitly configured to be shared. Tenants can create multiple networks, until they reach the thresholds specified by per-tenant Quotas (see next chapter for more details).  The network is the principal entity for the Neutron API. Ports and subnets must always be associated with a network. The following table describes the attributes of network objects. For each attribute, the CRUD column should be read as follows:
 +
 
 +
* C - the attribute can be used in '''create''' operations;
 +
* R - the attribute is returned in the response for '''show''' or '''list''' operations;
 +
* U - the value of attribute can be updated;
 +
* D - the value of the attribute can be removed;
 +
 
 
{| border="1" cellpadding="2" cellspacing="0"
 
{| border="1" cellpadding="2" cellspacing="0"
| attribute
+
|<style="font-weight:bold;">|Attribute
| Type  
+
|<style="font-weight:bold;">|Type  
| Required  
+
|<style="font-weight:bold;">|Required  
| CRUD  
+
|<style="font-weight:bold;">|CRUD  
| Default  
+
|<style="font-weight:bold;">|Default Value
 +
|<style="font-weight:bold;">|Validation Constraints
 
|-
 
|-
 
| id  
 
| id  
 
| uuid-str  
 
| uuid-str  
| -
+
| N/A
| R
+
| CR
| generated
+
| Generated
 +
| UUID_PATTERN
 
|-
 
|-
 
| name  
 
| name  
| str
+
| String
| Y
+
| No
 
| CRU  
 
| CRU  
| -
+
| None
 +
| N/A
 
|-
 
|-
 
| admin_state_up  
 
| admin_state_up  
| bool
+
| Bool
| N
+
| No
 
| CRU  
 
| CRU  
 
| True  
 
| True  
 +
| <nowiki>{ True | False }</nowiki>
 
|-
 
|-
 
| status  
 
| status  
| str
+
| String
| -
+
| N/A
 
| R  
 
| R  
| -
+
| N/A
 +
| N/A
 
|-
 
|-
| tenant_id
+
| subnets
| str (uuid?)  
+
| list(uuid-str)  
| N
+
| No
| CR (U?)
+
| R
| keystone-tenant
+
| Empty List
 +
| N/A
 
|-
 
|-
| subnets
+
| shared
| list(uuid)
+
| Bool
| N
+
| No
 
| CRU  
 
| CRU  
| []
+
| False
 +
| <nowiki>{ True | False }</nowiki>
 +
|-
 +
| tenant_id
 +
| uuid-str
 +
| No*
 +
| CR
 +
| N/A
 +
| N/A
 
|}
 
|}
  
 
=== Subnet ===
 
=== Subnet ===
/v2.0/subnets
+
A subnet represents an IP address block that can be used for assigning IP addresses to virtual instances. Each subnet must have a CIDR and must be associated with a network. IPs can be either selected from the whole subnet CIDR, or from "allocation pools" that can be specified by the user.
 +
 
 +
A subnet can also optionally have a gateway, a list of DNS name servers, and host routes. All this information will then be pushed to instances whose interfaces are associated with the subnet.
 
{| border="1" cellpadding="2" cellspacing="0"
 
{| border="1" cellpadding="2" cellspacing="0"
| attribute
+
|<style="font-weight:bold;">|Attribute
| Type  
+
|<style="font-weight:bold;">|Type  
| Required  
+
|<style="font-weight:bold;">|Required  
| CRUD  
+
|<style="font-weight:bold;">|CRUD  
| Default  
+
|<style="font-weight:bold;">|Default  
 +
|<style="font-weight:bold;">|Validation Constraints
 
|-
 
|-
 
| id  
 
| id  
 
| uuid-str  
 
| uuid-str  
| -  
+
| N/A
| R
+
| CR
| generated
+
| Generated
 +
| UUID_PATTERN
 +
|-
 +
| name
 +
| String
 +
| No
 +
| CRU
 +
| None
 +
| N/A
 
|-
 
|-
 
| network_id  
 
| network_id  
 
| uuid-str  
 
| uuid-str  
| Y
+
| Yes
 
| CR  
 
| CR  
| -
+
| Generated
 +
| Existing network identifier.
 
|-
 
|-
 
| ip_version  
 
| ip_version  
| int (4,6)
+
| int  
| Y
+
| Yes
 
| CR  
 
| CR  
| -
+
| 4
 +
| <nowiki>{ 4 | 6 }</nowiki>
 
|-
 
|-
 
| cidr  
 
| cidr  
| str
+
| string
| Y
+
| Yes
 
| CR  
 
| CR  
| -
+
| N/A
 +
| Valid CIDR in the form <network_address>/<prefix>
 
|-
 
|-
 
| gateway_ip  
 
| gateway_ip  
| str
+
| string or null
| N
+
| No
 
| CRUD  
 
| CRUD  
| .1 of cidr
+
| First address in ''CIDR''
 +
| Valid IP address or null
 
|-
 
|-
 
| dns_nameservers  
 
| dns_nameservers  
| list[str]]
+
| list(str)
| N
+
| No
 
| CRU  
 
| CRU  
| config-option?
+
| None
 +
| Configurable maximum amount of nameservers per subnet. The default is 5.
 
|-
 
|-
 
| allocation_pools  
 
| allocation_pools  
 
| list(dict)  
 
| list(dict)  
| N
+
| No
| CRU
+
| CR
| start + 1 to end - 1
+
| Every address in CIDR, excluding ''gateway IP'' if configured
 +
| Start/end of range must be valid IP
 
|-
 
|-
 
| host_routes  
 
| host_routes  
 
| list(dict)  
 
| list(dict)  
| N
+
| No
 +
| CRU
 +
| Default route to gateway_ip
 +
| {'destination': <CIDR>, "nexthop": <valid IP address>}. Configurable maximum amount of routes per subnet. The default is 20.
 +
|-
 +
| enable_dhcp
 +
| Bool
 +
| No
 
| CRU  
 
| CRU  
| default route to gateway_ip
+
| True
 +
| <nowiki>{ True | False }</nowiki>
 +
|-
 +
| tenant_id
 +
| uuid-str
 +
| No*
 +
| CR
 +
| N/A
 +
| N/A
 
|}
 
|}
  
 
=== Port ===
 
=== Port ===
/v2.0/ports
+
A port represents a virtual switch port on a logical network switch. Virtual instances attach their interfaces into ports. The logical port also defines the MAC address and the IP address(es) to be assigned to the interfaces plugged into them. When IP addresses are associated to a port, this also implies the port is associated with a subnet, as the IP address was taken from the allocation pool for a specific subnet.
 
{| border="1" cellpadding="2" cellspacing="0"
 
{| border="1" cellpadding="2" cellspacing="0"
| attribute
+
|<style="font-weight:bold;">|Attribute
| Type  
+
|<style="font-weight:bold;">|Type  
| Required  
+
|<style="font-weight:bold;">|Required  
| CRUD  
+
|<style="font-weight:bold;">|CRUD  
| Default  
+
|<style="font-weight:bold;">|Default  
 +
|<style="font-weight:bold;">|Validation Constraints
 
|-
 
|-
 
| id  
 
| id  
 
| uuid-str  
 
| uuid-str  
| -  
+
| N/A
| R
+
| CR
| generated
+
| Generated
 +
| UUID_PATTERN
 +
|-
 +
| name
 +
| String
 +
| No
 +
| CRU
 +
| None
 +
| N/A
 
|-
 
|-
 
| network_id  
 
| network_id  
 
| uuid-str  
 
| uuid-str  
| Y
+
| Yes
 
| CR  
 
| CR  
| -
+
| N/A
 +
| Existing network identifier.
 
|-
 
|-
 
| admin_state_up  
 
| admin_state_up  
 
| bool  
 
| bool  
| N
+
| No
 
| CRU  
 
| CRU  
 
| True  
 
| True  
 +
| <nowiki>{ True | False }</nowiki>
 
|-
 
|-
 
| status  
 
| status  
| str
+
| string
| -
+
| N/A
 
| R  
 
| R  
| -
+
| N/A
 +
| N/A
 
|-
 
|-
 
| mac_address  
 
| mac_address  
| str
+
| string
| N
+
| No
 
| CR  
 
| CR  
| generated
+
| Generated
 +
| Valid MAC in 6-octet form separated by colons.
 
|-
 
|-
 
| fixed_ips  
 
| fixed_ips  
 
| list(dict)  
 
| list(dict)  
| N
+
| No
| CR (U?)
+
| CRU
| allocated  
+
| Automatically allocated from pool.
 +
| Valid IP address and existing subnet identifier.
 
|-
 
|-
| host_routes
+
| device_id
| list(dict)
+
| str
| N
+
| No
| CR (U?)
+
| CRUD
| inherit from subnet
+
| None
 +
| No constraint
 
|-
 
|-
| device_id
+
| device_owner
 
| str  
 
| str  
| N
+
| No
 
| CRUD  
 
| CRUD  
| ""
+
| None
 +
| No constraint
 +
|-
 +
| tenant_id
 +
| uuid-str
 +
| No*
 +
| CR
 +
| N/A
 +
| N/A
 
|}
 
|}
  
params="{\"network\": {\"tenant_id\": \"default\", \"name\": \"net1\", \"admin_state_up\": true}}"
+
<nowiki>*</nowiki> The ''tenant_id'' attribute is mandatory if Neutron is not running with the Keystone Identity service
  
 
== General API information ==
 
== General API information ==
 +
=== Authentication and authorization ===
 +
Neutron uses the Keystone identity service (http://keystone.openstack.org) as the default authentication service.  When keystone is enabled Users submitting requests to the Neutron service must provide an authentication token in '''X-Auth-Token''' request header. The aforementioned token should have been obtained by authenticating with the keystone endpoint. For more information concerning authentication with Keystone, please refer to the Keystone documentation. When keystone is enabled, it is not mandatory to specify tenant_id for resources in '''create''' requests, as the tenant identifier will be derived from the Authentication token. Please note that the default authorization settings only allow administrative users to create resources on behalf of a different tenant.
 +
 +
Neutron uses information received from Keystone to authorize user requests. Neutron handles two kind of authorization policies:
 +
* Operation-based: policy specifying access criteria for specific operations, possibly with fine-grained control over specific attributes
 +
* Resource-based: whether access to specific resource might be granted or not according to the permissions configured for the resource (currently available only for the '''network''' resource)
 +
 +
The actual authorization policies enforced in Neutron might vary from deployment to deployment.
 +
 +
=== Request and Response types ===
 +
The [[OpenStack]] Neutron API supports the JSON data format. The format for both the request and the response can be specified either using the Accept header or adding the .json extension to the request URI.
 +
 +
'''Example: Request/Response with Headers: JSON'''
 +
 +
Request:
 +
  
=== Authentication ===
+
<pre><nowiki>
 +
POST /v1.0/tenants/tenantX/networks HTTP/1.1
 +
Host 127.0.0.1:9696
 +
Content-Type application/json
 +
Accept application/json
 +
Content-Length 57
  
=== Authorization ===
+
{
 +
"network":
 +
    {
 +
      "name": "net-name",
 +
      "admin_state_up": true
 +
    }
 +
}
 +
</nowiki></pre>
  
==== Action-Based policies ====
+
Response:
ciao
 
==== Resource-Based policies ====
 
ciao
 
  
=== Request and Response types ===
 
  
=== Synchronous vs Asynchronous Plugin Behavior ===
+
<pre><nowiki>
 +
HTTP/1.1 200 Accepted
 +
Content-Type application/json
 +
Content-Length 204
 +
 
 +
{
 +
"network":
 +
    {
 +
    "status": "ACTIVE",
 +
    "subnets": [],
 +
    "name": "net-name",
 +
    "admin_state_up": true,
 +
    "tenant_id": "388a70781bae4ca895f17b7f6293eb70",
 +
    "shared": false, "id": "2a4017ef-31ff-496a-9294-e96ecc3bc9c9"
 +
    }
 +
}
 +
</nowiki></pre>
 +
 
 +
'''''NOTE: We have still to finalize a decision concerning XML support.''''' [https://blueprints.launchpad.net/neutron/+spec/quantum-v2-api-xml Quantum v2 API XML blueprint]
 +
 
 +
=== Filtering  and Column Selection ===
 +
The Neutron API supports filtering based on all top level attributes of a resource. Filters are applicable to all '''list''' requests. For instance:
 +
 
 +
 
 +
<pre><nowiki>
 +
GET /v2.0/networks?name=foobar
 +
</nowiki></pre>
 +
 
 +
will return all the networks whose name is foobar. When multiple filters are specified, the Neutron API will return only objects that satisfy all the filters, this applying an AND condition among filters. Neutron does not offer a mechanisms for ORing filters. To this aim, the user can submit a distinct request for each filters, and then build a set on the client-side from received responses.
 +
 
 +
By default, Neutron returns all attributes for any Show or List call.  The Neutron API has a mechanism to limit the set of attributes returned (e.g., return just 'id').  Attributes returned from the Neutron API can be controller using the '''fields''' query parameter. For example the following request:
  
=== MAC allocation policy ===
 
  
xxx
+
<pre><nowiki>
 +
GET /v2.0/networks.json?fields=id&fields=name
 +
</nowiki></pre>
  
=== IP Adress Management ===
+
will return only '''id''' and '''name''' for each network.
  
yyy
+
=== Synchronous vs Asynchronous Plugin Behavior ===
 +
The Neutron API presents a logical model of network connectivity consisting of networks, ports, and subnets. It is up to the Neutron plugin to communicate with the underlying infrastructure to ensure packet forwarding is consistent with the logical model. A plugin might perform these operations asynchronously. This means that when an API client modifies the logical model using an HTTP POST, PUT, or DELETE, the API call may return prior to the plugin performing any modifications to underlying virtual and/or physical switching devices. The only guarantee an API client has is that all subsequent API calls will properly reflect the changed logical model. As a concrete example, consider the case where a client uses an HTTP PUT to set the attachment for a port. There is no guarantee that packets sent by the interface named in the attachment will be forwarded immediately once the HTTP call returns. However, there is a guarantee that a subsequent HTTP GET to view the attachment on that port would return the new attachment value. The "status" attribute, available for '''network''' and '''port''' resources might be used to understand whether the Neutron plugin has successfully completed the configuration of the interested resource.
  
 
=== Bulk Create Operations ===
 
=== Bulk Create Operations ===
yeah I start with bulk
+
The Neutron API allow for creating several objects of the same type in the same API request. Bulk create operations use exactly the same API as singleton create operations, with the only difference being that a list of objects, rather than a single object, is specified in the request body.
 +
 
 +
Bulk operations are always performed atomically, meaning that either all or none of the objects in the request body are created. Should the particular plugin does not support atomic operations, Neutron API will emulate the atomic behavior, thus ensuring users might expect the same behavior regardless of the particular plugin running in the backend.
 +
 
 +
Neutron might be deployed without support for bulk operations. In that case a '''400 Bad Request''' error will be returned when the client attempts a bulk create operation.
 +
 
 +
For more details concerning how to submit bulk requests to the Neutron API, please refer to create operations discussed in the next chapter.
  
 
=== Quotas ===
 
=== Quotas ===
 
+
[tbd] Yong to contribute
[tbd] This is for Yong
 
  
 
=== Notifications ===
 
=== Notifications ===
[tbd] This is for Yong
+
[tbd] Yong to contribute
  
 
=== Extensions ===
 
=== Extensions ===
 +
The Neutron API is extensible. Extensions serve several purposes:
 +
 +
* They allow the introduction of new features in the API without requiring a version change;
 +
* They allow the introduction of vendor specific niche functionality
 +
* They act as a proving ground for experimental functionalities which might be included in a future version of the API.
 +
 +
Applications can programmatically determine what extensions are available by performing a GET on the v2.0/extensions URI.  Extensions may also be queried individually by their unique alias by performing a GET on the /v2.0/extensions/alias_name. This provides the simplest method of checking if an extension is available as an unavailable extension will issue an itemNotFound (404) response. Existing core API resources can be extended with new actions or extra attributes. Also, new resources can also be added as extensions. Extensions usually have tags that prevent clash with other extensions defining attributes and/or resources with the same name, and with core resources and attributes. As an extension might not be supported by all plugin, availability of an extension will vary with deployments and the specific plugin in use.
  
 
=== Faults ===
 
=== Faults ===
 +
If a failure occurs while processing a request, the Neutron API returns an error response. Neutron uses only standard HTTP error codes. 4xx errors are indicative of problems in the particular request being sent from the client.
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
| Error
 +
|-
 +
|<style="text-align:center" |4>|400 Bad Request
 +
|-
 +
|-
 +
|-
 +
|-
 +
|<style="text-align:center" |2>|404 Not Found
 +
|-
 +
|-
 +
|<style="text-align:center" |3>|409 Conflict
 +
|-
 +
|-
 +
|-
 +
|<style="text-align:center" |2>|400 Bad Request
 +
|-
 +
|-
 +
| 500 Internal server error
 +
|-
 +
| 503 [[ServiceUnavailable]]
 +
|}
 +
 +
Users submitting requests to the Neutron API might also receive the following errors:
 +
 +
* 401 Unauthorized - if invalid credentials are provided
 +
* 403 Forbidden - If the user cannot access a specific resource or perform the requested operation.
  
 
== API Operations ==
 
== API Operations ==
 +
=== List Networks ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| GET
 +
| /networks
 +
|}
  
=== List Network ===
+
This operation returns the list of all the network the tenants has access to. This includes networks owned by tenant and shared networks. By default, network objects will be returned with all their attributes. Users can control which attribute should be returned by using the ''field'' query parameter.  Responses can be filtered by specifying search criteria on the query string. Only exact match supported at the moment.
 +
 
 +
Normal Response Code: 200
 +
 
 +
Error Response Codes: Unauthorized (401), Bad Request (400)
 +
 
 +
'''JSON Request and Response sample''':
 +
 
 +
Request
 +
 
 +
 
 +
<pre><nowiki>
 +
GET /v2.0/networks
 +
Accept: application/json
 +
</nowiki></pre>
 +
 
 +
Response
 +
 
 +
 
 +
<pre><nowiki>
 +
{
 +
  "networks": [
 +
  {
 +
    "status": "ACTIVE",
 +
    "subnets": [],
 +
    "name": "network_1",
 +
    "admin_state_up": true,
 +
    "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
 +
    "id": "3a06dfc7-d239-4aad-9a57-21cd171c72e5",
 +
    "shared": false
 +
  },
 +
  {
 +
    "status": "ACTIVE",
 +
    "subnets": [],
 +
    "name": "network-2",
 +
    "admin_state_up": true,
 +
    "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
 +
    "id": "7db8c5a4-6eb0-478d-856b-7cfda2b25e13",
 +
    "shared": false
 +
  },
 +
  {
 +
    "status": "ACTIVE",
 +
    "subnets": ["e12f0c45-46e3-446a-b207-9474b27687a6"],
 +
    "name": "network_3",
 +
    "admin_state_up": true,
 +
    "tenant_id": "ed680f49ff714162ab3612d7876ffce5",
 +
    "id": "afc75773-640e-403c-9fff-62ba98db1f19",
 +
    "shared": true
 +
  }
 +
]
 +
}
 +
</nowiki></pre>
  
 
=== Show Network ===
 
=== Show Network ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| GET
 +
| /networks/'''<network_id>'''
 +
|}
 +
 +
This operation returns the complete list of attributes for the network whose identifier is specified in the request URI, assuming the network exists and the user making the request is authorized to access it. The set of attributes which is actually returned by the API can be controller through the ''field'' query parameter.
 +
 +
Normal Response Code: 200
 +
 +
Error Response Codes: Unauthorized (401), Bad Request (400), Not Found (404)
 +
 +
'''JSON Request and Response sample''':
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
GET /v2.0/networks/afc75773-640e-403c-9fff-62ba98db1f19
 +
Accept: application/json
 +
</nowiki></pre>
 +
 +
Response:
 +
 +
 +
<pre><nowiki>
 +
{
 +
  "network":
 +
  {
 +
    "status": "ACTIVE",
 +
    "subnets": ["e12f0c45-46e3-446a-b207-9474b27687a6"],
 +
    "name": "network_3",
 +
    "admin_state_up": true,
 +
    "shared": false,
 +
    "tenant_id": "ed680f49ff714162ab3612d7876ffce5",
 +
    "id": "afc75773-640e-403c-9fff-62ba98db1f19"
 +
  }
 +
}
 +
</nowiki></pre>
  
 
=== Create Network ===
 
=== Create Network ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| POST
 +
| /networks
 +
|}
 +
 +
This operation will create a new Neutron network. The identifier of the newly created network is returned in the response. The ''shared'' attribute can be used to create a ''public'' network, i.e.: a network which is shared with all other tenants. However, the current model of the Neutron API allows only for either completely private or completely open networks. More sophisticated mechanisms for specifying ACLs on networks will come in future releases of the API.
 +
 +
Moreover, control of the '''shared''' attribute could be reserved to particular users only, such as administrators. In this case, regular users trying to create a shared network will receive a '''403 - Forbidden''' error.
 +
 +
Normal Response Code: 200
 +
 +
Error Response Codes: Unauthorized (401), Bad Request (400)
 +
 +
'''JSON Request and Response sample''':
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
POST v2.0/networks.json
 +
Content-Type: application/json
 +
Accept: application/json
 +
 +
{
 +
"network":
 +
  {
 +
    "name": "sample_network",
 +
    "admin_state_up": false
 +
  }
 +
}
 +
</nowiki></pre>
 +
 +
Response:
 +
 +
 +
<pre><nowiki>
 +
'status': '201'
 +
'content-length': '194'
 +
'content-type': 'application/json;
 +
 +
{
 +
  "network":
 +
    {
 +
      "status": "ACTIVE",
 +
      "subnets": [],
 +
      "name": "sample_network",
 +
      "admin_state_up": false,
 +
      "shared": false,
 +
      "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
 +
      "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
 +
    }
 +
}
 +
</nowiki></pre>
  
 
==== Bulk version ====
 
==== Bulk version ====
 +
The bulk version of operation allows for creating several networks with a single request. The behavior of the bulk create operation is always atomic: either all networks in the request body are created, or none of them is created. To this aim, a list of networks must be supplied in the request body, as follows:
  
==== Note about 'public' networks (permissions 0644) ====
+
'''JSON Request and Response sample''':
  
sono proprio stronzo
+
Request:
 +
 
 +
 
 +
<pre><nowiki>
 +
POST v2.0/networks.json
 +
 
 +
Content-Type: application/json
 +
Accept: application/json
 +
 
 +
{
 +
"networks": [
 +
  {
 +
    "name": "sample_network_1",
 +
    "admin_state_up": false
 +
  },
 +
  {
 +
    "name": "sample_network_2",
 +
    "admin_state_up": false
 +
  }]
 +
}
 +
</nowiki></pre>
  
 
=== Update Network ===
 
=== Update Network ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| PUT
 +
| /networks/''<network-id>''
 +
|}
 +
 +
The update network operation allow users for updating some attributes of a network object, such as name and admin_state_up. Attributes such as tenant_id cannot be updated. If an attempt is made to update such attributes a 422 'Unprocesable Entity' error will be returned.
 +
 +
Users authorized to control the ''shared'' attribute are also allowed to change it. While sharing a previously private network is always possible, the opposite is not always true. If the user attempts to turn private a shared network with subnets and/or ports belonging to tenants different from the network owner, a ''409 Conflict'' error will be returned.
 +
 +
''Note'': Update operations in Neutron adopt patch semantics. This implies that the Neutron API does not require the user to send the whole resource to be updated, but just the attributes that the user wishes to update, as reported in the example below.
 +
 +
Normal Response Code: 200 Ok
 +
 +
Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found
 +
 +
'''JSON Request and Response sample''':
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
PUT /v2.0/networks/fc68ea2c-b60b-4b4f-bd82-94ec81110766.json
 +
 +
Content-Type: application/json
 +
Accept: application/json
 +
 +
{
 +
  "network":
 +
    {
 +
      "name": "updated_name"
 +
    }
 +
}
 +
</nowiki></pre>
 +
 +
Response:
 +
 +
 +
<pre><nowiki>
 +
status: 200
 +
content-length: 192
 +
content-type: application/json
 +
 +
{
 +
  "network":
 +
    {"status": "ACTIVE",
 +
    "subnets": [],
 +
    "name": "updated_name",
 +
    "admin_state_up": false,
 +
    "shared": false,
 +
      "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
 +
      "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"}}
 +
</nowiki></pre>
  
 
=== Delete Network ===
 
=== Delete Network ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| DELETE
 +
| /networks/'''<network_id>'''
 +
|}
 +
 +
'''JSON Request and Response sample''':
 +
 +
This operation will remove a Neutron network, and all its associated subnets, provided that no port is currently configured on the network. If ports are still configured on the network being removed, a 409 error will be returned.
 +
 +
Normal Response Code: 204
 +
 +
Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Network in Use.
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
DELETE /v2.0/networks/fc68ea2c-b60b-4b4f-bd82-94ec81110766
 +
 +
Content-Type: application/json
 +
Accept: application/json
 +
</nowiki></pre>
 +
 +
Response:
 +
 +
 +
<pre><nowiki>
 +
status: 204
 +
</nowiki></pre>
  
 
=== List Subnets ===
 
=== List Subnets ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| GET
 +
| /subnets
 +
|}
 +
 +
This operation will return a list of subnets objects the tenant has access to. Default policy settings will return exclusively subnets owned by the tenant submitting the request, unless the request is submitted by an user with administrative rigths. Users can control which attributes should be returned using the ''fields'' query parameter as discussed in the previous chapter. Moreover, results can be filtered using query string parameters as discussed in the previous chapter.
 +
 +
This operation does not require a reques body.
 +
 +
Normal Response Code: 200 Ok
 +
 +
Error Response Codes: 401 Unauthorized
 +
 +
'''JSON Request and Response sample''':
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
GET v2.0/subnets.json
 +
 +
Accept: application/json
 +
</nowiki></pre>
 +
 +
Response:
 +
 +
 +
<pre><nowiki>
 +
status: 200
 +
content-length: 607
 +
content-type: application/json
 +
 +
{
 +
  "subnets": [
 +
  {
 +
    "name": "",
 +
    "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
 +
    "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
 +
    "allocation_pools": [{"start": "10.10.0.2", "end": "10.10.0.254"}],
 +
    "gateway_ip": "10.10.0.1",
 +
    "ip_version": 4,
 +
    "cidr": "10.10.0.0/24",
 +
    "id": "4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861",
 +
    "enable_dhcp": true
 +
    },
 +
    {
 +
      "name": "",
 +
      "network_id": "afc75773-640e-403c-9fff-62ba98db1f19",
 +
      "tenant_id": "ed680f49ff714162ab3612d7876ffce5",
 +
      "allocation_pools": [{"start": "10.0.0.2", "end": "10.0.0.254"}],
 +
      "gateway_ip": "10.0.0.1",
 +
      "ip_version": 4,
 +
      "cidr": "10.0.0.0/24",
 +
      "id": "e12f0c45-46e3-446a-b207-9474b27687a6",
 +
      "enable_dhcp": true
 +
    }]
 +
}
 +
</nowiki></pre>
  
 
=== Show Subnet ===
 
=== Show Subnet ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| GET
 +
| /subnets/''<subnet-id>''
 +
|}
 +
 +
This operation returns data about the subnet specified in the request URI. Users can control which attributes should be returned using the ''fields'' query parameter as discussed in the previous chapter. If the user submitting the request is not authorized to access the requested subnet, or if the requested subnet does not exist, a 404 error will be returned.
 +
 +
This operation does not require a request body.
 +
 +
Normal Response Code: 200 Ok
 +
 +
Error Response Codes: 400 Bad Request, 401 Unauthorized, 404 Not Found
 +
 +
'''JSON Request and Response sample''':
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
GET /v2.0/subnets/4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861
 +
 +
Accept: application/json
 +
</nowiki></pre>
 +
 +
Response:
 +
 +
 +
<pre><nowiki>
 +
status: 200
 +
content-length: 309
 +
content-type: application/json
 +
 +
{
 +
  "subnet":
 +
    {
 +
    "name": "",
 +
    "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
 +
    "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
 +
    "allocation_pools": [{"start": "10.10.0.2", "end": "10.10.0.254"}],
 +
    "gateway_ip": "10.10.0.1",
 +
    "ip_version": 4,
 +
    "cidr": "10.10.0.0/24",
 +
    "id": "4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861",
 +
    "enable_dhcp": false,
 +
    }
 +
}
 +
</nowiki></pre>
  
 
=== Create Subnet ===
 
=== Create Subnet ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| POST
 +
| /subnets
 +
|}
 +
 +
This operation creates a new subnet on a specific network. The identifier of the network, '''network_id''' is mandatory. The user must also specify the '''cidr''' for the subnet, in the form ''<network_address>/<prefix>''. The remaining parameters are optional.
 +
 +
By default, Neutron creates IP v4 subnets. In order to create an IP v6 subnet, users must specify the value ''6'' for the '''ip_version''' attribute in the request body. Please note that Neutron does not make any attempt to derive the correct IP version from the provided CIDR. If the parameter for the gateway address, '''gateway_ip''' is not specified, then Neutron will allocate an address from the subnet's cidr for the subnet's gateway. In order to specify a subnet without a gateway, users should specify the value ''null'' for the '''gateway_ip''' attribute in the request body.  If allocation pools (attribute '''allocation_pools''') are not specified, Neutron will automatically allocate pools for covering all IP addresses in the CIDR, excluding the address reserved for the subnet gateway. Otherwise users can explicitly specify allocation pools as shown in the example below.
 +
 +
Finally, a subnet by default will leverage DHCP for distributing addresses to VMs. If a different strategy is used, such as, for instance, file system IP configuration injection, the ''enable_dhcp'' attribute should be explicitly set to False in a ''create_subnet'' request.
 +
 +
Normal Response Code: 201 Created
 +
 +
Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found
 +
 +
'''JSON Request and Response sample''':
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
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"}]
 +
  }
 +
}
 +
}}
 +
 +
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}
 +
}
 +
</nowiki></pre>
  
 
==== Bulk version ====
 
==== Bulk version ====
 +
This operation allows for creating several subnets with a single request. To this aim, a list of subnets must be supplied in the request body. The behavior of the operation is always atomic, meaning that either all subnets are created, or none is created.
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
POST /v2.0/subnets
 +
Content-Type: application/json
 +
Accept: application/json
 +
 +
{
 +
  "subnets": [
 +
    {
 +
      "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
 +
      "ip_version": 4,
 +
      "cidr": "10.0.4.0/24",
 +
    }
 +
    {
 +
      "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
 +
      "ip_version": 4,
 +
      "cidr": "10.0.5.0/24",
 +
    }
 +
  ]
 +
}
 +
</nowiki></pre>
  
 
=== Update Subnet ===
 
=== Update Subnet ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| PUT
 +
| /subnets/''<subnet-id>''
 +
|}
 +
 +
This operation updates information concerning a subnet. Some attributes, such as IP version ('''ip_version'''), CIDR ('''cidr'''), and IP allocation pools (''''allocation_pools''') cannot be updated. Attempting to update these attributes will result in a 400 Bad Request error.
 +
 +
After updating ''host_routes'' and ''dns_nameservers'' attributes, there is no guarantee about when these changes will be reflected on running VM instances. The only responsibility of the Neutron API is to update the data model with the new information. When these information are then propagated on running VMs depends on the mechanism used for providing them with IP configuration. In case of DHCP, this will happen as soon as the VMs send a new DHCP request, and therefore it is likely to happen either when the DHCP lease expires or when the VM is rebooted.
 +
 +
''Note'': Update operations in Neutron adopt patch semantics. This implies that the Neutron API does not require the user to send the whole resource to be updated, but just the attributes that the user wishes to update, as reported in the example below
 +
 +
Normal Response Code: 200 Ok
 +
 +
Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 400 Bad Request
 +
 +
'''JSON Request and Response sample''':
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
PUT /v2.0/subnets/9436e561-47bf-436a-b1f1-fe23a926e031
 +
 +
Content-Type: application/json
 +
Accept: application/json
 +
 +
{
 +
  "subnet":
 +
    {
 +
      "gateway_ip": "10.0.3.254",
 +
      "name": "new_name"
 +
    }
 +
}
 +
</nowiki></pre>
 +
 +
Response:
 +
 +
 +
<pre><nowiki>
 +
status: 200
 +
content-length: 316
 +
content-type: application/json
 +
 +
{
 +
  "subnet":
 +
  {
 +
    "name": "new_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.254",
 +
    "ip_version": 4,
 +
    "cidr": "10.0.3.0/24",
 +
    "enable_dhcp": true,
 +
    "id": "9436e561-47bf-436a-b1f1-fe23a926e031"
 +
  }
 +
}
 +
</nowiki></pre>
  
 
=== Delete Subnet ===
 
=== Delete Subnet ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| DELETE
 +
| /subnets/''<subnetid>''
 +
|}
 +
 +
This operation remove a subnet from a Neutron network. The operation will fail if IPs from the subnet being removed are still allocated.
 +
 +
Normal Response Code: 204
 +
 +
Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict
 +
 +
'''JSON Request and Response sample''':
  
=== List Ports ===
+
Request:
 +
 
 +
 
 +
<pre><nowiki>
 +
DELETE /v2.0/subnets/9436e561-47bf-436a-b1f1-fe23a926e031
 +
 
 +
Accept: application/json
 +
</nowiki></pre>
  
=== Show Port ===
+
Response:
  
=== Create Port ===
 
  
==== Bulk version ====
+
<pre><nowiki>
 +
Status: 204
 +
</nowiki></pre>
  
=== Update Port ===
+
=== List Ports ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| GET
 +
| /ports
 +
|}
  
=== Delete Port ===
+
This operation will return a list of ports objects the tenant has access to. Default policy settings will return exclusively subnets owned by the tenant submitting the request, unless the request is submitted by an user with administrative rigths. Users can control which attributes should be returned using the ''fields'' query parameter as discussed in the previous chapter. Moreover, results can be filtered using query string parameters as discussed in the previous chapter.
  
== API usage samples ==
+
This operation does not require a reques body.
  
Find a bunch of common uses cases and then post request and response formats
+
Normal Response code: 200
  
== Basic JSON example ==
+
Error Response Code: 401 Unauthorized
Create a network, a subnet on that network, and a port on that network.  Remember that the port is likely to be created by Nova on behalf of a tenant.
 
  
POST /v2.0/networks
+
'''JSON Request and Response sample''':
  
 
Request:
 
Request:
Line 290: Line 1,013:
  
 
<pre><nowiki>
 
<pre><nowiki>
 +
GET /v2.0/ports.json HTTP/1.1
 +
accept: application/json
 +
</nowiki></pre>
 +
 +
Response:
 +
 +
 +
<pre><nowiki>
 +
Status: 200
 +
Content-Type: application/json
 +
Content-Length: 805
 +
 
{
 
{
  "network": {
+
    "ports": [
      "name" : "net1"
+
        {
      "tenant_id": a4fc5328-c270-4891-845a-e61c9153d261
+
            "admin_state_up": true,
      "admin_state_up": true
+
            "device_id": "257614cc-e178-4c92-9c61-3b28d40eca44",
  }
+
            "device_owner": "",
 +
            "fixed_ips": [
 +
                {
 +
                    "ip_address": "192.168.111.3",
 +
                    "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
 +
                }
 +
            ],
 +
            "id": "24e6637e-c521-45fc-8b8b-d7331aa3c99f",
 +
            "mac_address": "fa:16:3e:0f:3f:b5",
 +
            "name": "",
 +
            "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
 +
            "status": "ACTIVE",
 +
            "tenant_id": "cf1a5775e766426cb1968766d0191908"
 +
        },
 +
        {
 +
            "admin_state_up": true,
 +
            "device_id": "d266f9de-fe2c-4705-93b3-9da71168c93b",
 +
            "device_owner": "",
 +
            "fixed_ips": [
 +
                {
 +
                    "ip_address": "192.168.111.2",
 +
                    "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
 +
                }
 +
            ],
 +
            "id": "e54dfd9b-ce6e-47f7-af47-1609cfd1cdb0",
 +
            "mac_address": "fa:16:3e:f5:41:7f",
 +
            "name": "",
 +
            "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
 +
            "status": "ACTIVE",
 +
            "tenant_id": "cf1a5775e766426cb1968766d0191908"
 +
        }
 +
    ]
 
}
 
}
 +
</nowiki></pre>
 +
 +
=== Show Port ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| GET
 +
| /ports/''port-id''
 +
|}
 +
 +
This operation will return information regarding the port specified in the request URI. If the port does not exist or the user submitting the request is not authorized to access it, a 404 error is returned.
 +
 +
Normal Response code: 200
 +
 +
Error Response Code: 400 Bad Request, 401 Unauthorized, 404 Not Found
 +
 +
'''JSON Request and Response sample''':
 +
 +
Request:
 +
 +
 +
<pre><nowiki>
 +
GET /v2.0/ports/ebe69f1e-bc26-4db5-bed0-c0afb4afe3db.json
 +
accept: application/json
 
</nowiki></pre>
 
</nowiki></pre>
  
Line 303: Line 1,094:
  
 
<pre><nowiki>
 
<pre><nowiki>
 +
Status: 200
 +
Content-Type: application/json
 +
Content-Length: 410
 +
 
{
 
{
  "network": {
+
    "port": {
      "status": "ACTIVE",  
+
        "admin_state_up": true,
      "subnets": [],
+
        "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
      "name": "net1",
+
        "device_owner": "",
      "admin_state_up": true,  
+
        "fixed_ips": [
      "tenant_id": "a4fc5328-c270-4891-845a-e61c9153d261",  
+
            {
      "id": "c4863456-2c40-44f2-ab9f-63f978a8a4f3"
+
                "ip_address": "192.168.111.4",
 +
                "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
 +
            }
 +
        ],
 +
        "id": "ebe69f1e-bc26-4db5-bed0-c0afb4afe3db",
 +
        "mac_address": "fa:16:3e:a6:50:c1",
 +
        "name": "port1",
 +
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
 +
        "status": "ACTIVE",
 +
        "tenant_id": "cf1a5775e766426cb1968766d0191908"
 
     }
 
     }
 
}
 
}
 
</nowiki></pre>
 
</nowiki></pre>
  
POST /v2.0/subnets
+
=== Create Port ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| POST  
 +
| /ports
 +
|}
 +
 
 +
This operation creates a new Neutron port. The network where the port shall be created ('''network_id''' parameter) in the request body, must be specified. Optionally, user can also specify the following parameters:
 +
 
 +
* A symbolic name for the port
 +
* MAC address
 +
* Administrative state (True: Up, False: Down)
 +
* Fixed IPs
 +
** Specifying just a subnet id, Neutron allocates the first available IP from that subnet to the port
 +
** Specifying both a subnet id and an IP address, Neutron will try to allocate the specified address to the port
 +
* Identifier of the device attached to the port (e.g.: VM identifier)
 +
* Identifier of the owner of the device attached to the port (e.g.: DHCP agent identifier)
 +
 
 +
Normal Response code: 201
 +
 
 +
Error Response Code: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict
 +
 
 +
'''JSON Request and Response sample''':
  
 
Request:
 
Request:
Line 321: Line 1,149:
  
 
<pre><nowiki>
 
<pre><nowiki>
 +
POST /v2.0/ports.json HTTP/1.1
 +
Content-Length: 158
 +
content-type: application/json
 +
accept: application/json
 +
 
{
 
{
  "subnet": {
+
    "port": {
      "network_id": "98bd8391-199f-4440-824d-8659e4906786",
+
        "admin_state_up": true,
      "ip_version": 4,
+
        "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
      "cidr": "10.0.0.0/24",
+
        "name": "port1",
  }
+
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12"
 +
    }
 
}
 
}
 
</nowiki></pre>
 
</nowiki></pre>
  
 
Response:
 
Response:
 +
 +
 +
<pre><nowiki>
 +
Status: 201
 +
Content-Type: application/json; charset=UTF-8
 +
Content-Length: 410
 +
 +
{
 +
    "port": {
 +
        "admin_state_up": true,
 +
        "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
 +
        "device_owner": "",
 +
        "fixed_ips": [
 +
            {
 +
                "ip_address": "192.168.111.4",
 +
                "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
 +
            }
 +
        ],
 +
        "id": "ebe69f1e-bc26-4db5-bed0-c0afb4afe3db",
 +
        "mac_address": "fa:16:3e:a6:50:c1",
 +
        "name": "port1",
 +
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
 +
        "status": "ACTIVE",
 +
        "tenant_id": "cf1a5775e766426cb1968766d0191908"
 +
    }
 +
}
 +
</nowiki></pre>
 +
 +
==== Bulk version ====
 +
This operation allows for creating several ports with a single request. To this aim, a list of ports must be supplied in the request body. The Neutron API always guarantees the atomic completion of the bulk operation.
 +
 +
Bulk Request example:
  
  
 
<pre><nowiki>
 
<pre><nowiki>
 
{
 
{
"subnet": {
+
    "ports": [
    "id": "e76a23fe-b028-47b8-a765-858b65c0f857",
+
        {
    "network_id": "98bd8391-199f-4440-824d-8659e4906786",
+
        "admin_state_up": true,
    "ip_version": 4,
+
        "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
    "cidr": "10.0.0.0/24",
+
        "name": "port1",
    "gateway_ip": "10.0.0.1",
+
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12"
    "dns_nameservers": ["8.8.8.8"],
+
        },
    "allocation_pools": [ { "start" : "10.0.0.2", "end": "10.0.0.254"}],
+
        {
    "host_routes": [],
+
        "admin_state_up": true,
}
+
        "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
 +
        "name": "port2",
 +
        "network_id": "2cd34a97-e087-75fb-9904-dd12937009ea"
 +
        }
 +
    ]
 
}
 
}
 
</nowiki></pre>
 
</nowiki></pre>
  
POST /v2.0/ports
+
=== Update Port ===
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| UPDATE
 +
| /ports/''<port-id>''
 +
|}
 +
 
 +
This operation can be used for updating information on a port, such as the symbolic name and the associated IPs. When IPs for a port are updated, the previously associated IPs are removed, returned to the respective subnets allocation pools, and replaced by the IPs specified in the body for the Update request. In other words, the behavior of this operation is to replace the '''fixed_ip''' attribute when it is specified in the request body. If the new IP addresses are invalid (e.g.: already in use), the operation fail and the existing IP addresses are not disassociated from the port.
 +
 
 +
Please note that the only responsibility of the API is to update the data model with the new IP association information. The way in which IP addresses are actually updated on running VMs depends on the particular mechanism used to propagate IP configuration. In case of DHCP, this would happen either when the DHCP lease expires, or when the VM is rebooted.
 +
 
 +
Normal Response code: 200
 +
 
 +
Error Response Code: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict
 +
 
 +
'''JSON Request and Response sample''':
 +
 
 +
Request:
  
  
 
<pre><nowiki>
 
<pre><nowiki>
 +
PUT /v2.0/ports/1d8591f4-7b62-428e-857d-e82a15e5a7f1.json HTTP/1.1
 +
Content-Length: 63
 +
content-type: application/json
 +
accept: application/json
 +
 
{
 
{
  "port": {  
+
    "port": {
    "network_id": "98bd8391-199f-4440-824d-8659e4906786",
+
        "device_id": "37b4f622-5e17-4dca-bf67-7338c5b7dd63"
     "device_id": "32aeb491-4e78-4c24-8ab8-363daa65aa4d"
+
     }
  }
 
 
}
 
}
 
</nowiki></pre>
 
</nowiki></pre>
Line 364: Line 1,257:
  
 
<pre><nowiki>
 
<pre><nowiki>
 +
Status: 200
 +
Content-Type: application/json;
 +
Content-Length: 410
 +
 
{
 
{
  "port": {  
+
    "port": {
    "id": "b08a3807-5d3b-4ab8-95ce-3ed5aa28bdf6",
+
        "admin_state_up": true,
    "network_id": "98bd8391-199f-4440-824d-8659e4906786",
+
        "device_id": "37b4f622-5e17-4dca-bf67-7338c5b7dd63",
    "admin_state_up": True,
+
        "fixed_ips": [
    "status": "ACTIVE",
+
            {
    "mac_address": "ca:fe:de:ad:be:ef",
+
                "ip_address": "192.168.111.4",
    "fixed_ips": [ "10.0.0.2" ],
+
                "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
    "host_routes": [ { "destination": "0.0.0.0/0", "nexthop" : "10.0.0.1" },
+
            }
                          { "destination": "10.0.0.0/24", "nexthop": Null }],
+
        ],
    "device_id": "32aeb491-4e78-4c24-8ab8-363daa65aa4d",
+
        "id": "1d8591f4-7b62-428e-857d-e82a15e5a7f1",
  }  
+
        "mac_address": "fa:16:3e:70:d2:8c",
 +
        "name": "port2",
 +
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
 +
        "status": "ACTIVE",
 +
        "tenant_id": "cf1a5775e766426cb1968766d0191908"
 +
    }
 
}
 
}
 
</nowiki></pre>
 
</nowiki></pre>
  
== Other capabilities ==
+
=== Delete Port ===
* supports filtering based on all top level attributes of an API entity.  For example, GET /v2.0/networks?name=foobar
+
{| border="1" cellpadding="2" cellspacing="0"
* by default, returns all attributes for any Show or List call.  Has mechanism to limit the set of attributes returned (e.g., return just 'id').  Also has "verbose" mechanism to 'explode' UUID references within a returned object.  For example, doing a GET on network, and having a GET on a network return the fully populated data for all associated subnets.
+
|<style="font-weight: bold;">|Verb
 +
|<style="font-weight: bold;">|URI
 +
|-
 +
| DELETE
 +
| /ports/''<port-id>''  
 +
|}
 +
 
 +
This operation removes a port from a Neutron network. If IP addresses are associated with the port, they are returned to the respective subnets allocation pools.
 +
 
 +
Normal Response code: 204
 +
 
 +
Error Response Code: 401 Unauthorized, 403 Forbidden, 404 Not Found
 +
 
 +
'''JSON Request and Response sample''':
  
== Notable Non-IPAM Changes from v1.1 ==
+
Request:
* ports are flattened to be a top level resource.  Goal was to be able to search over ports without knowing net-id, and have searches return results from multiple networks (e.g., all ports associated with a device)
 
* bulk create operations for networks, ports, and subnets  (idea is to more efficiently handle creating many items?)
 
* tenant-id is not longer represented in the URL.  This is more inline with other openstack services.
 
* no notion of an attachment and attachment-id.  Instead, service integrating with Quantum (e.g., Nova) must be aware of port-ids, and communicate the binding between a port-id and a vswitch/pswitch port to Quantum.  This simplifies the API, and the Nova / Quantum integration.
 
  
== Open Questions ==
 
(not a complete list, please add)
 
  
* Does each subnet + port need a tenant-id, or does it inherit the tenant-id of the network?  How does this interact with the Authz need to delegate control of a port?
+
<pre><nowiki>
* With bulk create, how are errors handled if there is a failure in adding one of the items?
+
DELETE /v2.0/ports/ebe69f1e-bc26-4db5-bed0-c0afb4afe3db.json
* How to best represent fixed IPs on a port?  How to best view the allocated IPs on a subnet?  Should ports have a reference to the subnet so you can easily get all ports with IPs on the subnet?  Or should subnet have attribute or sub-url for all allocated ports?
+
accept: application/json
** How about modifying the fixed_ips_v* fields of Port to be addresses + prefix length or, better, (IP address, subnet ID) pairs? In that case, only one fixed_ips field is necessary, since each subnet indicates the IP version, and we can have a list mixing IPv4 and IPv6 addresses: [{"address": "192.168.1.1", "subnet_id": "fabdaafb-a723-4e59-8b0a-3d28239df66a"}, {"address": "fe80::ca2a:14ff:fe43:...", "subnet_id": "..."}].
+
</nowiki></pre>
* Is there no way of detaching a interface from a port or moving it between networks now?  (Or could this still be achieved on the nova side of things?)
+
 
* It would be nice if, as well as the this API documentation, there was a description of how you bind an interface (or tunnel endpoint, or whatever else) to a port.  It's nicer to have it written out than having to reason it out of the [[QuantumManager]] and friends.
+
Response:
* How do we specify some kind of limit on the 'list' attributes?  I suspect we would not want to allow someone specifying a thousand DNS servers for a subnet.  Should all list attributes have a MAX_LEN specified?
+
 
* Do we need port to have hosts information, the subnet's hosts are not enough?
+
 
 +
<pre><nowiki>
 +
status: 204
 +
</nowiki></pre>

Latest revision as of 05:28, 11 September 2014

Neutron v2 API

This page is a draft spec and may not reflect the actual implementation.

Refer to http://developer.openstack.org/api-ref-networking-v2.html for the latest.

Overview

Neutron is a project to provide virtual networking services between devices managed by the OpenStack compute service. This document presents and discusses version 2.0 of the Neutron API. For more information on the Neutron project, and additional documentation, please visit http://wiki.openstack.org/Neutron, and docs.openstack.org. We welcome feedback, comments, and bug reports at https://bugs.launchpad.net/neutron.

The v2.0 API represents a combination of the Quantum v1.1 API with some of the most essential IPAM capabilities from the Melange API . These IPAM capabilities focus on being able to associate IP address blocks and other network configuration required by a network device (e.g., default gateway, dns-servers) with a Neutron Network, and then being able to allocate an IP address out of such a block and associate it with a device that is attached to the network via a Neutron Port.

The v2.0 API does this by introducing a new entity, called a Subnet. Subnets can represent the binding of either a IPv4 or IPv6 address block to a previously created Quantum network, and each Neutron Network commonly has one or more subnets. When a port is created on the network, by default it will be allocated an available fixed IP address out of one the designated subnets for each IP version. When the Port is destroyed, the allocated addresses return to the pool of available IPs on the subnet. Users of the Neutron API can either choose a specific IP address from the block, or let Neutron choose the first available IP address.

Please note that version 1.x of the Neutron API has been removed from the source code tree. In order to use v1.x API, an earlier release of Neutron should be installed.

High-level flow

  • Tenant creates a network (e.g., "net1")
  • Tenant creates a subnet (e.g., "10.0.0.0/24"), which implicitly associates the address space with that network. This association creates a binding of the address space to the previously created network. While it is common to say, that a subnet is represented by an IPv4 or IPv6 address range, the address range alone is not a subnet. Rather it is the binding of the address space to the network, which creates the subnet.
  • Tenant boots a VM, specifying a single NIC connected to "net1" (e.g.: nova boot --image <image_name> --nic net-id=<id_of_net1> <server_name>)
  • Nova contacts Neutron and creates a port1 on net1.
  • Neutron assigns an IP to port1 is assigned IP. (The IP is chosen by Neutron)
  • Tenant destroys VM.
  • Nova contacts Neutron and destroys port1. Allocated IP is returned to the pool of available IP address.

The Plugin

While the Neutron API represents the interface of the virtual network service to users and other services, these network services are implemented by a component called "Plugin". Plugins may adopt different techniques and technologies for providing isolated virtual networks to tenant, as well as providing other services such as IP address management. Users should not be concerned about the particular plugin employed as far as the API discussed in this document is concerned, as every plugin will implement all the operations included in the Neutron v2 API.

However, some plugins might expose additional capabilities through API extensions, discussed later in this document. For more information about the extensions exposed by a particular plugin, please refer to the plugin documentation.

Concepts

The Neutron v2 API manages three kind of entities:

  • Network, representing isolated virtual Layer-2 domains; a network can also be regarded as a virtual (or logical) switch;
  • Subnet, representing IPv4 or IPv6 address blocks from which IPs to be assigned to VMs on a given network are selected.
  • Port, representing virtual (or logical) switch ports on a given network.

All entities, discussed in detail in the rest of this chapter, support the basic CRUD operations with POST/GET/PUT/DELETE verbs, and have an auto-generated unique identifier.

Network

A network is a virtual isolated layer-2 broadcast domain which is typically reserved to the tenant who created it, unless the network has been explicitly configured to be shared. Tenants can create multiple networks, until they reach the thresholds specified by per-tenant Quotas (see next chapter for more details). The network is the principal entity for the Neutron API. Ports and subnets must always be associated with a network. The following table describes the attributes of network objects. For each attribute, the CRUD column should be read as follows:

  • C - the attribute can be used in create operations;
  • R - the attribute is returned in the response for show or list operations;
  • U - the value of attribute can be updated;
  • D - the value of the attribute can be removed;
Attribute Type Required CRUD Default Value Validation Constraints
id uuid-str N/A CR Generated UUID_PATTERN
name String No CRU None N/A
admin_state_up Bool No CRU True { True | False }
status String N/A R N/A N/A
subnets list(uuid-str) No R Empty List N/A
shared Bool No CRU False { True | False }
tenant_id uuid-str No* CR N/A N/A

Subnet

A subnet represents an IP address block that can be used for assigning IP addresses to virtual instances. Each subnet must have a CIDR and must be associated with a network. IPs can be either selected from the whole subnet CIDR, or from "allocation pools" that can be specified by the user.

A subnet can also optionally have a gateway, a list of DNS name servers, and host routes. All this information will then be pushed to instances whose interfaces are associated with the subnet.

Attribute Type Required CRUD Default Validation Constraints
id uuid-str N/A CR Generated UUID_PATTERN
name String No CRU None N/A
network_id uuid-str Yes CR Generated Existing network identifier.
ip_version int Yes CR 4 { 4 | 6 }
cidr string Yes CR N/A Valid CIDR in the form <network_address>/<prefix>
gateway_ip string or null No CRUD First address in CIDR Valid IP address or null
dns_nameservers list(str) No CRU None Configurable maximum amount of nameservers per subnet. The default is 5.
allocation_pools list(dict) No CR Every address in CIDR, excluding gateway IP if configured Start/end of range must be valid IP
host_routes list(dict) No CRU Default route to gateway_ip {'destination': <CIDR>, "nexthop": <valid IP address>}. Configurable maximum amount of routes per subnet. The default is 20.
enable_dhcp Bool No CRU True { True | False }
tenant_id uuid-str No* CR N/A N/A

Port

A port represents a virtual switch port on a logical network switch. Virtual instances attach their interfaces into ports. The logical port also defines the MAC address and the IP address(es) to be assigned to the interfaces plugged into them. When IP addresses are associated to a port, this also implies the port is associated with a subnet, as the IP address was taken from the allocation pool for a specific subnet.

Attribute Type Required CRUD Default Validation Constraints
id uuid-str N/A CR Generated UUID_PATTERN
name String No CRU None N/A
network_id uuid-str Yes CR N/A Existing network identifier.
admin_state_up bool No CRU True { True | False }
status string N/A R N/A N/A
mac_address string No CR Generated Valid MAC in 6-octet form separated by colons.
fixed_ips list(dict) No CRU Automatically allocated from pool. Valid IP address and existing subnet identifier.
device_id str No CRUD None No constraint
device_owner str No CRUD None No constraint
tenant_id uuid-str No* CR N/A N/A

* The tenant_id attribute is mandatory if Neutron is not running with the Keystone Identity service

General API information

Authentication and authorization

Neutron uses the Keystone identity service (http://keystone.openstack.org) as the default authentication service. When keystone is enabled Users submitting requests to the Neutron service must provide an authentication token in X-Auth-Token request header. The aforementioned token should have been obtained by authenticating with the keystone endpoint. For more information concerning authentication with Keystone, please refer to the Keystone documentation. When keystone is enabled, it is not mandatory to specify tenant_id for resources in create requests, as the tenant identifier will be derived from the Authentication token. Please note that the default authorization settings only allow administrative users to create resources on behalf of a different tenant.

Neutron uses information received from Keystone to authorize user requests. Neutron handles two kind of authorization policies:

  • Operation-based: policy specifying access criteria for specific operations, possibly with fine-grained control over specific attributes
  • Resource-based: whether access to specific resource might be granted or not according to the permissions configured for the resource (currently available only for the network resource)

The actual authorization policies enforced in Neutron might vary from deployment to deployment.

Request and Response types

The OpenStack Neutron API supports the JSON data format. The format for both the request and the response can be specified either using the Accept header or adding the .json extension to the request URI.

Example: Request/Response with Headers: JSON

Request:


POST /v1.0/tenants/tenantX/networks HTTP/1.1
Host 127.0.0.1:9696
Content-Type application/json
Accept application/json
Content-Length 57

{
 "network":
    {
      "name": "net-name",
      "admin_state_up": true
    }
}

Response:


HTTP/1.1 200 Accepted
Content-Type application/json
Content-Length 204

{
 "network":
    {
     "status": "ACTIVE",
     "subnets": [],
     "name": "net-name",
     "admin_state_up": true,
     "tenant_id": "388a70781bae4ca895f17b7f6293eb70",
     "shared": false, "id": "2a4017ef-31ff-496a-9294-e96ecc3bc9c9"
    }
}

NOTE: We have still to finalize a decision concerning XML support. Quantum v2 API XML blueprint

Filtering and Column Selection

The Neutron API supports filtering based on all top level attributes of a resource. Filters are applicable to all list requests. For instance:


GET /v2.0/networks?name=foobar

will return all the networks whose name is foobar. When multiple filters are specified, the Neutron API will return only objects that satisfy all the filters, this applying an AND condition among filters. Neutron does not offer a mechanisms for ORing filters. To this aim, the user can submit a distinct request for each filters, and then build a set on the client-side from received responses.

By default, Neutron returns all attributes for any Show or List call. The Neutron API has a mechanism to limit the set of attributes returned (e.g., return just 'id'). Attributes returned from the Neutron API can be controller using the fields query parameter. For example the following request:


GET /v2.0/networks.json?fields=id&fields=name

will return only id and name for each network.

Synchronous vs Asynchronous Plugin Behavior

The Neutron API presents a logical model of network connectivity consisting of networks, ports, and subnets. It is up to the Neutron plugin to communicate with the underlying infrastructure to ensure packet forwarding is consistent with the logical model. A plugin might perform these operations asynchronously. This means that when an API client modifies the logical model using an HTTP POST, PUT, or DELETE, the API call may return prior to the plugin performing any modifications to underlying virtual and/or physical switching devices. The only guarantee an API client has is that all subsequent API calls will properly reflect the changed logical model. As a concrete example, consider the case where a client uses an HTTP PUT to set the attachment for a port. There is no guarantee that packets sent by the interface named in the attachment will be forwarded immediately once the HTTP call returns. However, there is a guarantee that a subsequent HTTP GET to view the attachment on that port would return the new attachment value. The "status" attribute, available for network and port resources might be used to understand whether the Neutron plugin has successfully completed the configuration of the interested resource.

Bulk Create Operations

The Neutron API allow for creating several objects of the same type in the same API request. Bulk create operations use exactly the same API as singleton create operations, with the only difference being that a list of objects, rather than a single object, is specified in the request body.

Bulk operations are always performed atomically, meaning that either all or none of the objects in the request body are created. Should the particular plugin does not support atomic operations, Neutron API will emulate the atomic behavior, thus ensuring users might expect the same behavior regardless of the particular plugin running in the backend.

Neutron might be deployed without support for bulk operations. In that case a 400 Bad Request error will be returned when the client attempts a bulk create operation.

For more details concerning how to submit bulk requests to the Neutron API, please refer to create operations discussed in the next chapter.

Quotas

[tbd] Yong to contribute

Notifications

[tbd] Yong to contribute

Extensions

The Neutron API is extensible. Extensions serve several purposes:

  • They allow the introduction of new features in the API without requiring a version change;
  • They allow the introduction of vendor specific niche functionality
  • They act as a proving ground for experimental functionalities which might be included in a future version of the API.

Applications can programmatically determine what extensions are available by performing a GET on the v2.0/extensions URI. Extensions may also be queried individually by their unique alias by performing a GET on the /v2.0/extensions/alias_name. This provides the simplest method of checking if an extension is available as an unavailable extension will issue an itemNotFound (404) response. Existing core API resources can be extended with new actions or extra attributes. Also, new resources can also be added as extensions. Extensions usually have tags that prevent clash with other extensions defining attributes and/or resources with the same name, and with core resources and attributes. As an extension might not be supported by all plugin, availability of an extension will vary with deployments and the specific plugin in use.

Faults

If a failure occurs while processing a request, the Neutron API returns an error response. Neutron uses only standard HTTP error codes. 4xx errors are indicative of problems in the particular request being sent from the client.

Error
4>|400 Bad Request
2>|404 Not Found
3>|409 Conflict
2>|400 Bad Request
500 Internal server error
503 ServiceUnavailable

Users submitting requests to the Neutron API might also receive the following errors:

  • 401 Unauthorized - if invalid credentials are provided
  • 403 Forbidden - If the user cannot access a specific resource or perform the requested operation.

API Operations

List Networks

Verb URI
GET /networks

This operation returns the list of all the network the tenants has access to. This includes networks owned by tenant and shared networks. By default, network objects will be returned with all their attributes. Users can control which attribute should be returned by using the field query parameter. Responses can be filtered by specifying search criteria on the query string. Only exact match supported at the moment.

Normal Response Code: 200

Error Response Codes: Unauthorized (401), Bad Request (400)

JSON Request and Response sample:

Request


GET /v2.0/networks
Accept: application/json

Response


{
  "networks": [
  {
    "status": "ACTIVE",
    "subnets": [],
    "name": "network_1",
    "admin_state_up": true,
    "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
    "id": "3a06dfc7-d239-4aad-9a57-21cd171c72e5",
    "shared": false
  },
  {
    "status": "ACTIVE",
    "subnets": [],
    "name": "network-2",
    "admin_state_up": true,
    "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
    "id": "7db8c5a4-6eb0-478d-856b-7cfda2b25e13",
    "shared": false
  },
  {
    "status": "ACTIVE",
    "subnets": ["e12f0c45-46e3-446a-b207-9474b27687a6"],
    "name": "network_3",
    "admin_state_up": true,
    "tenant_id": "ed680f49ff714162ab3612d7876ffce5",
    "id": "afc75773-640e-403c-9fff-62ba98db1f19",
    "shared": true
   }
 ]
}

Show Network

Verb URI
GET /networks/<network_id>

This operation returns the complete list of attributes for the network whose identifier is specified in the request URI, assuming the network exists and the user making the request is authorized to access it. The set of attributes which is actually returned by the API can be controller through the field query parameter.

Normal Response Code: 200

Error Response Codes: Unauthorized (401), Bad Request (400), Not Found (404)

JSON Request and Response sample:

Request:


GET /v2.0/networks/afc75773-640e-403c-9fff-62ba98db1f19
Accept: application/json

Response:


{
  "network":
  {
    "status": "ACTIVE",
    "subnets": ["e12f0c45-46e3-446a-b207-9474b27687a6"],
    "name": "network_3",
    "admin_state_up": true,
    "shared": false,
    "tenant_id": "ed680f49ff714162ab3612d7876ffce5",
    "id": "afc75773-640e-403c-9fff-62ba98db1f19"
  }
}

Create Network

Verb URI
POST /networks

This operation will create a new Neutron network. The identifier of the newly created network is returned in the response. The shared attribute can be used to create a public network, i.e.: a network which is shared with all other tenants. However, the current model of the Neutron API allows only for either completely private or completely open networks. More sophisticated mechanisms for specifying ACLs on networks will come in future releases of the API.

Moreover, control of the shared attribute could be reserved to particular users only, such as administrators. In this case, regular users trying to create a shared network will receive a 403 - Forbidden error.

Normal Response Code: 200

Error Response Codes: Unauthorized (401), Bad Request (400)

JSON Request and Response sample:

Request:


POST v2.0/networks.json
Content-Type: application/json
Accept: application/json

{
 "network":
  {
    "name": "sample_network",
    "admin_state_up": false
  }
}

Response:


'status': '201'
'content-length': '194'
'content-type': 'application/json;

{
  "network":
    {
      "status": "ACTIVE",
      "subnets": [],
      "name": "sample_network",
      "admin_state_up": false,
      "shared": false,
      "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
       "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
     }
}

Bulk version

The bulk version of operation allows for creating several networks with a single request. The behavior of the bulk create operation is always atomic: either all networks in the request body are created, or none of them is created. To this aim, a list of networks must be supplied in the request body, as follows:

JSON Request and Response sample:

Request:


POST v2.0/networks.json

Content-Type: application/json
Accept: application/json

{
"networks": [
   {
     "name": "sample_network_1",
     "admin_state_up": false
   },
   {
     "name": "sample_network_2",
     "admin_state_up": false
   }]
}

Update Network

Verb URI
PUT /networks/<network-id>

The update network operation allow users for updating some attributes of a network object, such as name and admin_state_up. Attributes such as tenant_id cannot be updated. If an attempt is made to update such attributes a 422 'Unprocesable Entity' error will be returned.

Users authorized to control the shared attribute are also allowed to change it. While sharing a previously private network is always possible, the opposite is not always true. If the user attempts to turn private a shared network with subnets and/or ports belonging to tenants different from the network owner, a 409 Conflict error will be returned.

Note: Update operations in Neutron adopt patch semantics. This implies that the Neutron API does not require the user to send the whole resource to be updated, but just the attributes that the user wishes to update, as reported in the example below.

Normal Response Code: 200 Ok

Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found

JSON Request and Response sample:

Request:


PUT /v2.0/networks/fc68ea2c-b60b-4b4f-bd82-94ec81110766.json

Content-Type: application/json
Accept: application/json

{
  "network":
    {
      "name": "updated_name"
    }
}

Response:


status: 200
content-length: 192
content-type: application/json

{
  "network":
    {"status": "ACTIVE",
     "subnets": [],
     "name": "updated_name",
     "admin_state_up": false,
     "shared": false,
      "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
      "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"}}

Delete Network

Verb URI
DELETE /networks/<network_id>

JSON Request and Response sample:

This operation will remove a Neutron network, and all its associated subnets, provided that no port is currently configured on the network. If ports are still configured on the network being removed, a 409 error will be returned.

Normal Response Code: 204

Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Network in Use.

Request:


DELETE /v2.0/networks/fc68ea2c-b60b-4b4f-bd82-94ec81110766

Content-Type: application/json
Accept: application/json

Response:


status: 204

List Subnets

Verb URI
GET /subnets

This operation will return a list of subnets objects the tenant has access to. Default policy settings will return exclusively subnets owned by the tenant submitting the request, unless the request is submitted by an user with administrative rigths. Users can control which attributes should be returned using the fields query parameter as discussed in the previous chapter. Moreover, results can be filtered using query string parameters as discussed in the previous chapter.

This operation does not require a reques body.

Normal Response Code: 200 Ok

Error Response Codes: 401 Unauthorized

JSON Request and Response sample:

Request:


GET v2.0/subnets.json

Accept: application/json

Response:


status: 200
content-length: 607
content-type: application/json

{
  "subnets": [
   {
     "name": "",
     "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
     "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
     "allocation_pools": [{"start": "10.10.0.2", "end": "10.10.0.254"}],
     "gateway_ip": "10.10.0.1",
     "ip_version": 4,
     "cidr": "10.10.0.0/24",
     "id": "4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861",
     "enable_dhcp": true
    },
    {
      "name": "",
      "network_id": "afc75773-640e-403c-9fff-62ba98db1f19",
      "tenant_id": "ed680f49ff714162ab3612d7876ffce5",
      "allocation_pools": [{"start": "10.0.0.2", "end": "10.0.0.254"}],
      "gateway_ip": "10.0.0.1",
      "ip_version": 4,
      "cidr": "10.0.0.0/24",
      "id": "e12f0c45-46e3-446a-b207-9474b27687a6",
      "enable_dhcp": true
     }]
}

Show Subnet

Verb URI
GET /subnets/<subnet-id>

This operation returns data about the subnet specified in the request URI. Users can control which attributes should be returned using the fields query parameter as discussed in the previous chapter. If the user submitting the request is not authorized to access the requested subnet, or if the requested subnet does not exist, a 404 error will be returned.

This operation does not require a request body.

Normal Response Code: 200 Ok

Error Response Codes: 400 Bad Request, 401 Unauthorized, 404 Not Found

JSON Request and Response sample:

Request:


GET /v2.0/subnets/4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861

Accept: application/json

Response:


status: 200
content-length: 309
content-type: application/json

{
  "subnet":
    {
     "name": "",
     "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
     "tenant_id": "c1210485b2424d48804aad5d39c61b8f",
     "allocation_pools": [{"start": "10.10.0.2", "end": "10.10.0.254"}],
     "gateway_ip": "10.10.0.1",
     "ip_version": 4,
     "cidr": "10.10.0.0/24",
     "id": "4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861",
     "enable_dhcp": false,
    }
}

Create Subnet

Verb URI
POST /subnets

This operation creates a new subnet on a specific network. The identifier of the network, network_id is mandatory. The user must also specify the cidr for the subnet, in the form <network_address>/<prefix>. The remaining parameters are optional.

By default, Neutron creates IP v4 subnets. In order to create an IP v6 subnet, users must specify the value 6 for the ip_version attribute in the request body. Please note that Neutron does not make any attempt to derive the correct IP version from the provided CIDR. If the parameter for the gateway address, gateway_ip is not specified, then Neutron will allocate an address from the subnet's cidr for the subnet's gateway. In order to specify a subnet without a gateway, users should specify the value null for the gateway_ip attribute in the request body. If allocation pools (attribute allocation_pools) are not specified, Neutron will automatically allocate pools for covering all IP addresses in the CIDR, excluding the address reserved for the subnet gateway. Otherwise users can explicitly specify allocation pools as shown in the example below.

Finally, a subnet by default will leverage DHCP for distributing addresses to VMs. If a different strategy is used, such as, for instance, file system IP configuration injection, the enable_dhcp attribute should be explicitly set to False in a create_subnet request.

Normal Response Code: 201 Created

Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found

JSON Request and Response sample:

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"}]
  }
}
}}

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}
}

Bulk version

This operation allows for creating several subnets with a single request. To this aim, a list of subnets must be supplied in the request body. The behavior of the operation is always atomic, meaning that either all subnets are created, or none is created.

Request:


POST /v2.0/subnets
Content-Type: application/json
Accept: application/json

{
  "subnets": [
    {
      "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
      "ip_version": 4,
       "cidr": "10.0.4.0/24",
    }
    {
      "network_id": "ed2e3c10-2e43-4297-9006-2863a2d1abbc",
      "ip_version": 4,
       "cidr": "10.0.5.0/24",
    }
   ]
}

Update Subnet

Verb URI
PUT /subnets/<subnet-id>

This operation updates information concerning a subnet. Some attributes, such as IP version (ip_version), CIDR (cidr), and IP allocation pools ('allocation_pools) cannot be updated. Attempting to update these attributes will result in a 400 Bad Request error.

After updating host_routes and dns_nameservers attributes, there is no guarantee about when these changes will be reflected on running VM instances. The only responsibility of the Neutron API is to update the data model with the new information. When these information are then propagated on running VMs depends on the mechanism used for providing them with IP configuration. In case of DHCP, this will happen as soon as the VMs send a new DHCP request, and therefore it is likely to happen either when the DHCP lease expires or when the VM is rebooted.

Note: Update operations in Neutron adopt patch semantics. This implies that the Neutron API does not require the user to send the whole resource to be updated, but just the attributes that the user wishes to update, as reported in the example below

Normal Response Code: 200 Ok

Error Response Codes: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 400 Bad Request

JSON Request and Response sample:

Request:


PUT /v2.0/subnets/9436e561-47bf-436a-b1f1-fe23a926e031

Content-Type: application/json
Accept: application/json

{
  "subnet":
    {
      "gateway_ip": "10.0.3.254",
      "name": "new_name"
    }
}

Response:


status: 200
content-length: 316
content-type: application/json

{
  "subnet":
   {
     "name": "new_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.254",
     "ip_version": 4,
     "cidr": "10.0.3.0/24",
     "enable_dhcp": true,
     "id": "9436e561-47bf-436a-b1f1-fe23a926e031"
   }
}

Delete Subnet

Verb URI
DELETE /subnets/<subnetid>

This operation remove a subnet from a Neutron network. The operation will fail if IPs from the subnet being removed are still allocated.

Normal Response Code: 204

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

JSON Request and Response sample:

Request:


DELETE /v2.0/subnets/9436e561-47bf-436a-b1f1-fe23a926e031

Accept: application/json

Response:


Status: 204

List Ports

Verb URI
GET /ports

This operation will return a list of ports objects the tenant has access to. Default policy settings will return exclusively subnets owned by the tenant submitting the request, unless the request is submitted by an user with administrative rigths. Users can control which attributes should be returned using the fields query parameter as discussed in the previous chapter. Moreover, results can be filtered using query string parameters as discussed in the previous chapter.

This operation does not require a reques body.

Normal Response code: 200

Error Response Code: 401 Unauthorized

JSON Request and Response sample:

Request:


GET /v2.0/ports.json HTTP/1.1
accept: application/json

Response:


Status: 200
Content-Type: application/json
Content-Length: 805

{
    "ports": [
        {
            "admin_state_up": true,
            "device_id": "257614cc-e178-4c92-9c61-3b28d40eca44",
            "device_owner": "",
            "fixed_ips": [
                {
                    "ip_address": "192.168.111.3",
                    "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
                }
            ],
            "id": "24e6637e-c521-45fc-8b8b-d7331aa3c99f",
            "mac_address": "fa:16:3e:0f:3f:b5",
            "name": "",
            "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
            "status": "ACTIVE",
            "tenant_id": "cf1a5775e766426cb1968766d0191908"
        },
        {
            "admin_state_up": true,
            "device_id": "d266f9de-fe2c-4705-93b3-9da71168c93b",
            "device_owner": "",
            "fixed_ips": [
                {
                    "ip_address": "192.168.111.2",
                    "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
                }
            ],
            "id": "e54dfd9b-ce6e-47f7-af47-1609cfd1cdb0",
            "mac_address": "fa:16:3e:f5:41:7f",
            "name": "",
            "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
            "status": "ACTIVE",
            "tenant_id": "cf1a5775e766426cb1968766d0191908"
        }
    ]
}

Show Port

Verb URI
GET /ports/port-id

This operation will return information regarding the port specified in the request URI. If the port does not exist or the user submitting the request is not authorized to access it, a 404 error is returned.

Normal Response code: 200

Error Response Code: 400 Bad Request, 401 Unauthorized, 404 Not Found

JSON Request and Response sample:

Request:


GET /v2.0/ports/ebe69f1e-bc26-4db5-bed0-c0afb4afe3db.json
accept: application/json

Response:


Status: 200
Content-Type: application/json
Content-Length: 410

{
    "port": {
        "admin_state_up": true,
        "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
        "device_owner": "",
        "fixed_ips": [
            {
                "ip_address": "192.168.111.4",
                "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
            }
        ],
        "id": "ebe69f1e-bc26-4db5-bed0-c0afb4afe3db",
        "mac_address": "fa:16:3e:a6:50:c1",
        "name": "port1",
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
        "status": "ACTIVE",
        "tenant_id": "cf1a5775e766426cb1968766d0191908"
    }
}

Create Port

Verb URI
POST /ports

This operation creates a new Neutron port. The network where the port shall be created (network_id parameter) in the request body, must be specified. Optionally, user can also specify the following parameters:

  • A symbolic name for the port
  • MAC address
  • Administrative state (True: Up, False: Down)
  • Fixed IPs
    • Specifying just a subnet id, Neutron allocates the first available IP from that subnet to the port
    • Specifying both a subnet id and an IP address, Neutron will try to allocate the specified address to the port
  • Identifier of the device attached to the port (e.g.: VM identifier)
  • Identifier of the owner of the device attached to the port (e.g.: DHCP agent identifier)

Normal Response code: 201

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

JSON Request and Response sample:

Request:


POST /v2.0/ports.json HTTP/1.1
Content-Length: 158
content-type: application/json
accept: application/json

{
    "port": {
        "admin_state_up": true,
        "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
        "name": "port1",
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12"
    }
}

Response:


Status: 201
Content-Type: application/json; charset=UTF-8
Content-Length: 410

{
    "port": {
        "admin_state_up": true,
        "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
        "device_owner": "",
        "fixed_ips": [
            {
                "ip_address": "192.168.111.4",
                "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
            }
        ],
        "id": "ebe69f1e-bc26-4db5-bed0-c0afb4afe3db",
        "mac_address": "fa:16:3e:a6:50:c1",
        "name": "port1",
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
        "status": "ACTIVE",
        "tenant_id": "cf1a5775e766426cb1968766d0191908"
    }
}

Bulk version

This operation allows for creating several ports with a single request. To this aim, a list of ports must be supplied in the request body. The Neutron API always guarantees the atomic completion of the bulk operation.

Bulk Request example:


{
    "ports": [
        {
         "admin_state_up": true,
         "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
         "name": "port1",
         "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12"
        },
        {
         "admin_state_up": true,
         "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
         "name": "port2",
         "network_id": "2cd34a97-e087-75fb-9904-dd12937009ea"
        }
     ]
}

Update Port

Verb URI
UPDATE /ports/<port-id>

This operation can be used for updating information on a port, such as the symbolic name and the associated IPs. When IPs for a port are updated, the previously associated IPs are removed, returned to the respective subnets allocation pools, and replaced by the IPs specified in the body for the Update request. In other words, the behavior of this operation is to replace the fixed_ip attribute when it is specified in the request body. If the new IP addresses are invalid (e.g.: already in use), the operation fail and the existing IP addresses are not disassociated from the port.

Please note that the only responsibility of the API is to update the data model with the new IP association information. The way in which IP addresses are actually updated on running VMs depends on the particular mechanism used to propagate IP configuration. In case of DHCP, this would happen either when the DHCP lease expires, or when the VM is rebooted.

Normal Response code: 200

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

JSON Request and Response sample:

Request:


PUT /v2.0/ports/1d8591f4-7b62-428e-857d-e82a15e5a7f1.json HTTP/1.1
Content-Length: 63
content-type: application/json
accept: application/json

{
    "port": {
        "device_id": "37b4f622-5e17-4dca-bf67-7338c5b7dd63"
    }
}

Response:


Status: 200
Content-Type: application/json;
Content-Length: 410

{
    "port": {
        "admin_state_up": true,
        "device_id": "37b4f622-5e17-4dca-bf67-7338c5b7dd63",
        "fixed_ips": [
            {
                "ip_address": "192.168.111.4",
                "subnet_id": "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27"
            }
        ],
        "id": "1d8591f4-7b62-428e-857d-e82a15e5a7f1",
        "mac_address": "fa:16:3e:70:d2:8c",
        "name": "port2",
        "network_id": "6aeaf34a-c482-4bd3-9dc3-7faf36412f12",
        "status": "ACTIVE",
        "tenant_id": "cf1a5775e766426cb1968766d0191908"
    }
}

Delete Port

Verb URI
DELETE /ports/<port-id>

This operation removes a port from a Neutron network. If IP addresses are associated with the port, they are returned to the respective subnets allocation pools.

Normal Response code: 204

Error Response Code: 401 Unauthorized, 403 Forbidden, 404 Not Found

JSON Request and Response sample:

Request:


DELETE /v2.0/ports/ebe69f1e-bc26-4db5-bed0-c0afb4afe3db.json
accept: application/json

Response:


status: 204