summaryrefslogtreecommitdiff
path: root/nova/api/openstack/compute/contrib/multinic.py
diff options
context:
space:
mode:
authorAnthony Young <sleepsonthefloor@gmail.com>2012-01-09 14:02:02 -0800
committerAnthony Young <sleepsonthefloor@gmail.com>2012-01-13 09:06:55 -0800
commit60ff2e3b72b5a3c9200f8fc47aac01cdb610bdcf (patch)
treef3764b8c1f7d4247ad9bf653643e60e1b68fffb7 /nova/api/openstack/compute/contrib/multinic.py
parent26de3426d471c447cef1bd8a1129027821136241 (diff)
downloadnova-60ff2e3b72b5a3c9200f8fc47aac01cdb610bdcf.tar.gz
Implements blueprint separate-nova-volumeapi
* Moves openstack/v2 directory to compute and fixes tests accordingly * Moves some code from api/openstack/compute to shared location, for use by volume api * Implements basic volume functionality for types, volumes, and snapshots * Changes service name from osapi to osapi_compute (and adds osapi_volume) * Renames nova-api-os to nova-api-os-compute, adds nove-api-os-volume * Separate extension mechanism for compute and volume ** Removes flag osapi_extension and replaces with osapi_compute_extension and osapi_volume_extension * Updates the paste config * Fixes setup.py to include nova-os-api-compute and nova-os-api-volume * Fix bug in volume version code that occurred as result of trunk merge * Update integrated/test_volumes.py to use new endpoint Change-Id: I4c2e57c3cafd4e1a9e2ff3ce201c8cf28326afcd
Diffstat (limited to 'nova/api/openstack/compute/contrib/multinic.py')
-rw-r--r--nova/api/openstack/compute/contrib/multinic.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/contrib/multinic.py b/nova/api/openstack/compute/contrib/multinic.py
new file mode 100644
index 0000000000..18b95e63db
--- /dev/null
+++ b/nova/api/openstack/compute/contrib/multinic.py
@@ -0,0 +1,106 @@
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# 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.
+
+"""The multinic extension."""
+
+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
+
+
+LOG = logging.getLogger("nova.api.openstack.compute.contrib.multinic")
+
+
+# Note: The class name is as it has to be for this to be loaded as an
+# extension--only first character capitalized.
+class Multinic(extensions.ExtensionDescriptor):
+ """Multiple network support"""
+
+ name = "Multinic"
+ alias = "NMN"
+ namespace = "http://docs.openstack.org/compute/ext/multinic/api/v1.1"
+ updated = "2011-06-09T00:00:00+00:00"
+
+ def __init__(self, ext_mgr):
+ """Initialize the extension.
+
+ Gets a compute.API object so we can call the back-end
+ add_fixed_ip() and remove_fixed_ip() methods.
+ """
+
+ super(Multinic, self).__init__(ext_mgr)
+ self.compute_api = compute.API()
+
+ def get_actions(self):
+ """Return the actions the extension adds, as required by contract."""
+
+ actions = []
+
+ # Add the add_fixed_ip action
+ act = extensions.ActionExtension("servers", "addFixedIp",
+ self._add_fixed_ip)
+ actions.append(act)
+
+ # Add the remove_fixed_ip action
+ act = extensions.ActionExtension("servers", "removeFixedIp",
+ self._remove_fixed_ip)
+ actions.append(act)
+
+ 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."""
+
+ # Validate the input entity
+ if 'networkId' not in input_dict['addFixedIp']:
+ msg = _("Missing 'networkId' argument for addFixedIp")
+ raise exc.HTTPUnprocessableEntity(explanation=msg)
+
+ context = req.environ['nova.context']
+ instance = self._get_instance(context, id)
+ network_id = input_dict['addFixedIp']['networkId']
+ 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):
+ """Removes an IP from an instance."""
+
+ # Validate the input entity
+ if 'address' not in input_dict['removeFixedIp']:
+ msg = _("Missing 'address' argument for removeFixedIp")
+ raise exc.HTTPUnprocessableEntity(explanation=msg)
+
+ context = req.environ['nova.context']
+ instance = self._get_instance(context, id)
+ address = input_dict['removeFixedIp']['address']
+
+ try:
+ self.compute_api.remove_fixed_ip(context, instance, address)
+ except exceptions.FixedIpNotFoundForSpecificInstance:
+ LOG.exception(_("Unable to find address %r") % address)
+ raise exc.HTTPBadRequest()
+
+ return webob.Response(status_int=202)