diff options
| author | Eldar Nugaev <enugaev@griddynamics.com> | 2011-06-24 21:35:06 +0400 |
|---|---|---|
| committer | Eldar Nugaev <enugaev@griddynamics.com> | 2011-06-24 21:35:06 +0400 |
| commit | 4d3c1959edfbdd364a19e59aecd1579d136adade (patch) | |
| tree | 930cdee54abec2f4e0636957dc4aef2afa954764 | |
| parent | c2216547d0c55e32a4f8203129f4604f4ba004c7 (diff) | |
| parent | c5745c0cb61bb6ab375a1e52d5e203a7a0a76366 (diff) | |
| download | nova-4d3c1959edfbdd364a19e59aecd1579d136adade.tar.gz nova-4d3c1959edfbdd364a19e59aecd1579d136adade.tar.xz nova-4d3c1959edfbdd364a19e59aecd1579d136adade.zip | |
merge with kirill
| -rw-r--r-- | nova/api/openstack/contrib/floating_ips.py | 27 | ||||
| -rw-r--r-- | nova/tests/api/openstack/contrib/test_floating_ips.py | 39 |
2 files changed, 54 insertions, 12 deletions
diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index dc048869c..23864c352 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -43,7 +43,7 @@ def _translate_floating_ips_view(floating_ips): class FloatingIPController(object): - """The Volumes API controller for the OpenStack API.""" + """The Floating IPs API controller for the OpenStack API.""" _serialization_metadata = { 'application/xml': { @@ -98,15 +98,32 @@ class FloatingIPController(object): return {'released': ip} - def associate(self, req, id, body): + def associate(self, req, id_ip, body): + """ /floating_ips/ip or id/associate fixed ip in body """ context = req.environ['nova.context'] + floating_ip = self._get_ip_by_id(context, id_ip) - return {'associate': None} + fixed_ip = body['associate_address']['fixed_ip'] - def disassociate(self, req, id, body): + try: + self.network_api.associate_floating_ip(context, floating_ip, fixed_ip) + except rpc.RemoteError: + raise + + return {'associated': [floating_ip, fixed_ip]} + + def disassociate(self, req, id_ip, body): + """ POST /floating_ips/{ip | ip_id}/disassociate """ context = req.environ['nova.context'] - return {'disassociate': None} + floating_ip = self._get_ip_by_id(context, id_ip) + + try: + self.network_api.disassociate_floating_ip(context, floating_ip) + except rpc.RemoteError: + raise + + return {'disassociated': floating_ip} def _get_ip_by_id(self, context, value): """Checks that value is id and then returns its address. diff --git a/nova/tests/api/openstack/contrib/test_floating_ips.py b/nova/tests/api/openstack/contrib/test_floating_ips.py index 9e079c9b0..0faeaeb39 100644 --- a/nova/tests/api/openstack/contrib/test_floating_ips.py +++ b/nova/tests/api/openstack/contrib/test_floating_ips.py @@ -15,24 +15,33 @@ from nova import context from nova import db from nova import test + +import stubout +import webob + from nova.api.openstack.contrib.floating_ips import FloatingIPController from nova.api.openstack.contrib.floating_ips import \ _translate_floating_ip_view class FloatingIpTest(test.TestCase): - address = "10.10.10.10" + floating_ip_address = "10.10.10.10" + fixed_ip_address = '100.100.100.100' + + def _create_fixed_ip(self): + """Create a fixed ip object. Returns address as string""" + return db.fixed_ip_create(self.context, + {'address': self.fixed_ip_address}) def _create_floating_ip(self): - """Create a volume object.""" - host = "fake_host" + """Create a floating ip object. Returns address as string""" return db.floating_ip_create(self.context, - {'address': self.address, - 'host': host}) + {'address': self.floating_ip_address}) def setUp(self): super(FloatingIpTest, self).setUp() - self.floating_ips = FloatingIPController() + self.controller = FloatingIPController() + self.stubs = stubout.StubOutForTesting() self.context = context.get_admin_context() def test_translate_floating_ip_view(self): @@ -42,6 +51,22 @@ class FloatingIpTest(test.TestCase): view = _translate_floating_ip_view(floating_ip) self.assertTrue('floating_ip' in view) self.assertTrue(view['floating_ip']['id']) - self.assertEqual(view['floating_ip']['ip'], self.address) + self.assertEqual(view['floating_ip']['ip'], self.floating_ip_address) self.assertEqual(view['floating_ip']['fixed_ip'], None) self.assertEqual(view['floating_ip']['instance_id'], None) + + + def test_associate_by_address(self): + fixed_ip_address = self._create_fixed_ip() + floating_ip_address = self._create_floating_ip() + floating_ip = db.floating_ip_get_by_address(self.context, floating_ip_address) + + self.assertEqual(floating_ip['address'], self.floating_ip_address) + self.assertEqual(floating_ip['fixed_ip_id'], None) + body = {'associate_address': {'fixed_ip': self.fixed_ip_address}} + + req = webob.Request.blank('/v1.1/floating_ips//associate') + raise Exception(req.__dict__) + #self.controller.associate(req, self.floating_ip_address, body) + #self.assertEqual(floating_ip['fixed_ip'], self.fixed_ip_address) + |
