diff --git a/doc/api_samples/os-fixed-ips/fixedip-post-req.json b/doc/api_samples/os-fixed-ips/fixedip-post-req.json
new file mode 100644
index 0000000000..cf8ba0e0bd
--- /dev/null
+++ b/doc/api_samples/os-fixed-ips/fixedip-post-req.json
@@ -0,0 +1,3 @@
+{
+ "reserve": "None"
+}
\ No newline at end of file
diff --git a/doc/api_samples/os-fixed-ips/fixedip-post-req.xml b/doc/api_samples/os-fixed-ips/fixedip-post-req.xml
new file mode 100644
index 0000000000..e29b685be2
--- /dev/null
+++ b/doc/api_samples/os-fixed-ips/fixedip-post-req.xml
@@ -0,0 +1,2 @@
+
+None
\ No newline at end of file
diff --git a/doc/api_samples/os-fixed-ips/fixedips-get-resp.json b/doc/api_samples/os-fixed-ips/fixedips-get-resp.json
new file mode 100644
index 0000000000..d63c91559a
--- /dev/null
+++ b/doc/api_samples/os-fixed-ips/fixedips-get-resp.json
@@ -0,0 +1,8 @@
+{
+ "fixed_ip": {
+ "address": "192.168.1.1",
+ "cidr": "192.168.1.0/24",
+ "host": "host",
+ "hostname": "openstack"
+ }
+}
\ No newline at end of file
diff --git a/doc/api_samples/os-fixed-ips/fixedips-get-resp.xml b/doc/api_samples/os-fixed-ips/fixedips-get-resp.xml
new file mode 100644
index 0000000000..a9676721f3
--- /dev/null
+++ b/doc/api_samples/os-fixed-ips/fixedips-get-resp.xml
@@ -0,0 +1,7 @@
+
+
+ 192.168.1.0/24
+ openstack
+ host
+ 192.168.1.1
+
\ No newline at end of file
diff --git a/nova/tests/integrated/api_samples/os-fixed-ips/fixedip-post-req.json.tpl b/nova/tests/integrated/api_samples/os-fixed-ips/fixedip-post-req.json.tpl
new file mode 100644
index 0000000000..85ae4890ad
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-fixed-ips/fixedip-post-req.json.tpl
@@ -0,0 +1,3 @@
+{
+ "reserve": "%(reserve)s"
+}
diff --git a/nova/tests/integrated/api_samples/os-fixed-ips/fixedip-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-fixed-ips/fixedip-post-req.xml.tpl
new file mode 100644
index 0000000000..3896b24eb6
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-fixed-ips/fixedip-post-req.xml.tpl
@@ -0,0 +1,2 @@
+
+%(reserve)s
diff --git a/nova/tests/integrated/api_samples/os-fixed-ips/fixedips-get-resp.json.tpl b/nova/tests/integrated/api_samples/os-fixed-ips/fixedips-get-resp.json.tpl
new file mode 100644
index 0000000000..a3d11475bf
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-fixed-ips/fixedips-get-resp.json.tpl
@@ -0,0 +1,8 @@
+{
+ "fixed_ip": {
+ "cidr": "%(cidr)s",
+ "hostname": "%(hostname)s",
+ "host": "%(host)s",
+ "address": "%(address)s"
+ }
+}
diff --git a/nova/tests/integrated/api_samples/os-fixed-ips/fixedips-get-resp.xml.tpl b/nova/tests/integrated/api_samples/os-fixed-ips/fixedips-get-resp.xml.tpl
new file mode 100644
index 0000000000..3e9598f347
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-fixed-ips/fixedips-get-resp.xml.tpl
@@ -0,0 +1,7 @@
+
+
+ %(cidr)s
+ %(hostname)s
+ %(host)s
+ %(address)s
+
diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py
index a33b39da4d..bfa5a7b146 100644
--- a/nova/tests/integrated/test_api_samples.py
+++ b/nova/tests/integrated/test_api_samples.py
@@ -30,6 +30,7 @@ from nova.compute import api
from nova import context
from nova import db
from nova.db.sqlalchemy import models
+from nova import exception
from nova.network import api
from nova.network.manager import NetworkManager
from nova.openstack.common import cfg
@@ -355,7 +356,6 @@ class ApiSamplesTrap(ApiSampleTestBase):
do_not_approve_additions.append('os-config-drive')
do_not_approve_additions.append('os-coverage')
do_not_approve_additions.append('os-create-server-ext')
- do_not_approve_additions.append('os-fixed-ips')
do_not_approve_additions.append('os-flavor-access')
do_not_approve_additions.append('os-flavor-extra-specs')
do_not_approve_additions.append('os-flavor-rxtx')
@@ -1490,6 +1490,90 @@ class AgentsXmlTest(AgentsJsonTest):
ctype = "xml"
+class FixedIpJsonTest(ApiSampleTestBase):
+ extension_name = "nova.api.openstack.compute.contrib.fixed_ips.Fixed_ips"
+
+ def _get_flags(self):
+ f = super(FixedIpJsonTest, self)._get_flags()
+ f['osapi_compute_extension'] = CONF.osapi_compute_extension[:]
+ return f
+
+ def setUp(self):
+ super(FixedIpJsonTest, self).setUp()
+
+ fake_fixed_ips = [{'id': 1,
+ 'address': '192.168.1.1',
+ 'network_id': 1,
+ 'virtual_interface_id': 1,
+ 'instance_uuid': '1',
+ 'allocated': False,
+ 'leased': False,
+ 'reserved': False,
+ 'host': None},
+ {'id': 2,
+ 'address': '192.168.1.2',
+ 'network_id': 1,
+ 'virtual_interface_id': 2,
+ 'instance_uuid': '2',
+ 'allocated': False,
+ 'leased': False,
+ 'reserved': False,
+ 'host': None},
+ ]
+
+ def fake_fixed_ip_get_by_address(context, address):
+ for fixed_ip in fake_fixed_ips:
+ if fixed_ip['address'] == address:
+ return fixed_ip
+ raise exception.FixedIpNotFoundForAddress(address=address)
+
+ def fake_fixed_ip_get_by_address_detailed(context, address):
+ network = {'id': 1,
+ 'cidr': "192.168.1.0/24"}
+ host = {'host': "host",
+ 'hostname': 'openstack'}
+ for fixed_ip in fake_fixed_ips:
+ if fixed_ip['address'] == address:
+ return (fixed_ip, network, host)
+ raise exception.FixedIpNotFoundForAddress(address=address)
+
+ def fake_fixed_ip_update(context, address, values):
+ fixed_ip = fake_fixed_ip_get_by_address(context, address)
+ if fixed_ip is None:
+ raise exception.FixedIpNotFoundForAddress(address=address)
+ else:
+ for key in values:
+ fixed_ip[key] = values[key]
+
+ self.stubs.Set(db, "fixed_ip_get_by_address",
+ fake_fixed_ip_get_by_address)
+ self.stubs.Set(db, "fixed_ip_get_by_address_detailed",
+ fake_fixed_ip_get_by_address_detailed)
+ self.stubs.Set(db, "fixed_ip_update", fake_fixed_ip_update)
+
+ def test_fixed_ip_reserve(self):
+ """Reserve a Fixed IP"""
+ project = {'reserve': None}
+ response = self._do_post('os-fixed-ips/192.168.1.1/action',
+ 'fixedip-post-req',
+ project)
+ self.assertEqual(response.status, 202)
+
+ def test_get_fixed_ip(self):
+ """Return data about the given fixed ip."""
+ response = self._do_get('os-fixed-ips/192.168.1.1')
+ self.assertEqual(response.status, 200)
+ project = {'cidr': '192.168.1.0/24',
+ 'hostname': 'openstack',
+ 'host': 'host',
+ 'address': '192.168.1.1'}
+ return self._verify_response('fixedips-get-resp', project, response)
+
+
+class FixedIpXmlTest(FixedIpJsonTest):
+ ctype = "xml"
+
+
class AggregatesSampleJsonTest(ServersSampleBase):
extension_name = "nova.api.openstack.compute.contrib" + \
".aggregates.Aggregates"