summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2011-11-11 21:27:27 +0000
committerGerrit Code Review <review@openstack.org>2011-11-11 21:27:27 +0000
commit615c4df3201fce7ae95c1b50bcec7f212cfc2aa6 (patch)
tree48c2cf2bb2d51f2a621d3175154b8636ebddaf55 /nova/api
parentf492fced12078733c8a84e69d222ec52c2fce609 (diff)
parent6bd44ccb3a4bf8536f6bca9b81517d2b24c31f14 (diff)
downloadnova-615c4df3201fce7ae95c1b50bcec7f212cfc2aa6.tar.gz
nova-615c4df3201fce7ae95c1b50bcec7f212cfc2aa6.tar.xz
nova-615c4df3201fce7ae95c1b50bcec7f212cfc2aa6.zip
Merge "Converting fixed ip calls to use instance objects"
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/contrib/multinic.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/nova/api/openstack/contrib/multinic.py b/nova/api/openstack/contrib/multinic.py
index 85ff423aa..26968646d 100644
--- a/nova/api/openstack/contrib/multinic.py
+++ b/nova/api/openstack/contrib/multinic.py
@@ -15,12 +15,13 @@
"""The multinic extension."""
-from webob import exc
import webob
+from webob import exc
+from nova.api.openstack import extensions
from nova import compute
+from nova import exception
from nova import log as logging
-from nova.api.openstack import extensions
LOG = logging.getLogger("nova.api.multinic")
@@ -63,6 +64,13 @@ class Multinic(extensions.ExtensionDescriptor):
return actions
+ def _get_instance(self, context, instance_id):
+ try:
+ return self.compute_api.get(context, instance_id)
+ except exception.InstanceNotFound:
+ msg = _("Server not found")
+ raise exc.HTTPNotFound(msg)
+
def _add_fixed_ip(self, input_dict, req, id):
"""Adds an IP on a given network to an instance."""
@@ -71,10 +79,10 @@ class Multinic(extensions.ExtensionDescriptor):
msg = _("Missing 'networkId' argument for addFixedIp")
raise exc.HTTPUnprocessableEntity(explanation=msg)
- # Add the fixed IP
+ context = req.environ['nova.context']
+ instance = self._get_instance(context, id)
network_id = input_dict['addFixedIp']['networkId']
- self.compute_api.add_fixed_ip(req.environ['nova.context'], id,
- network_id)
+ self.compute_api.add_fixed_ip(context, instance, network_id)
return webob.Response(status_int=202)
def _remove_fixed_ip(self, input_dict, req, id):
@@ -85,11 +93,12 @@ class Multinic(extensions.ExtensionDescriptor):
msg = _("Missing 'address' argument for removeFixedIp")
raise exc.HTTPUnprocessableEntity(explanation=msg)
- # Remove the fixed IP
+ context = req.environ['nova.context']
+ instance = self._get_instance(context, id)
address = input_dict['removeFixedIp']['address']
+
try:
- self.compute_api.remove_fixed_ip(req.environ['nova.context'], id,
- address)
+ self.compute_api.remove_fixed_ip(context, instance, address)
except exceptions.FixedIpNotFoundForSpecificInstance:
LOG.exception(_("Unable to find address %r") % address)
raise exc.HTTPBadRequest()