summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/extended_floating_ips.py27
-rw-r--r--nova/api/openstack/compute/contrib/floating_ips.py30
2 files changed, 47 insertions, 10 deletions
diff --git a/nova/api/openstack/compute/contrib/extended_floating_ips.py b/nova/api/openstack/compute/contrib/extended_floating_ips.py
new file mode 100644
index 000000000..06f1fa903
--- /dev/null
+++ b/nova/api/openstack/compute/contrib/extended_floating_ips.py
@@ -0,0 +1,27 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 OpenStack Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License
+
+from nova.api.openstack import extensions
+
+
+class Extended_floating_ips(extensions.ExtensionDescriptor):
+ """Adds optional fixed_address to the add floating IP command."""
+
+ name = "ExtendedFloatingIps"
+ alias = "os-extended-floating-ips"
+ namespace = ("http://docs.openstack.org/compute/ext/"
+ "extended_floating_ips/api/v2")
+ updated = "2013-04-19T00:00:00+00:00"
diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py
index bf1246ccb..32cf1eece 100644
--- a/nova/api/openstack/compute/contrib/floating_ips.py
+++ b/nova/api/openstack/compute/contrib/floating_ips.py
@@ -198,10 +198,11 @@ class FloatingIPController(object):
class FloatingIPActionController(wsgi.Controller):
- def __init__(self, *args, **kwargs):
+ def __init__(self, ext_mgr=None, *args, **kwargs):
super(FloatingIPActionController, self).__init__(*args, **kwargs)
self.compute_api = compute.API()
self.network_api = network.API()
+ self.ext_mgr = ext_mgr
@wsgi.action('addFloatingIp')
def _add_floating_ip(self, req, id, body):
@@ -230,18 +231,27 @@ class FloatingIPActionController(wsgi.Controller):
msg = _('No fixed ips associated to instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
- # TODO(tr3buchet): this will associate the floating IP with the
- # first fixed_ip an instance has. This should be
- # changed to support specifying a particular fixed_ip if
- # multiple exist.
- if len(fixed_ips) > 1:
- msg = _('multiple fixed_ips exist, using the first: %s')
- LOG.warning(msg, fixed_ips[0]['address'])
+ fixed_address = None
+ if self.ext_mgr.is_loaded('os-extended-floating-ips'):
+ if 'fixed_address' in body['addFloatingIp']:
+ fixed_address = body['addFloatingIp']['fixed_address']
+ for fixed in fixed_ips:
+ if fixed['address'] == fixed_address:
+ break
+ else:
+ msg = _('Specified fixed address not assigned to instance')
+ raise webob.exc.HTTPBadRequest(explanation=msg)
+
+ if not fixed_address:
+ fixed_address = fixed_ips[0]['address']
+ if len(fixed_ips) > 1:
+ msg = _('multiple fixed_ips exist, using the first: %s')
+ LOG.warning(msg, fixed_address)
try:
self.network_api.associate_floating_ip(context, instance,
floating_address=address,
- fixed_address=fixed_ips[0]['address'])
+ fixed_address=fixed_address)
except exception.FloatingIpAssociated:
msg = _('floating ip is already associated')
raise webob.exc.HTTPBadRequest(explanation=msg)
@@ -318,6 +328,6 @@ class Floating_ips(extensions.ExtensionDescriptor):
return resources
def get_controller_extensions(self):
- controller = FloatingIPActionController()
+ controller = FloatingIPActionController(self.ext_mgr)
extension = extensions.ControllerExtension(self, 'servers', controller)
return [extension]