diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-01-10 12:31:48 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-01-10 12:31:48 +0000 |
| commit | fa43949c05ff4e5165baa2f0a0f1555e94bcf212 (patch) | |
| tree | 257727bde45442607e07ea2f27f554e74f0be243 /nova/api | |
| parent | ef6058a44649715d5215958475c444ad811fe491 (diff) | |
| parent | 26b24b7e2305d9aa179a9d257b715e6d67b75573 (diff) | |
| download | nova-fa43949c05ff4e5165baa2f0a0f1555e94bcf212.tar.gz nova-fa43949c05ff4e5165baa2f0a0f1555e94bcf212.tar.xz nova-fa43949c05ff4e5165baa2f0a0f1555e94bcf212.zip | |
Merge "Adds support for floating ip pools"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/v2/contrib/floating_ip_pools.py | 104 | ||||
| -rw-r--r-- | nova/api/openstack/v2/contrib/floating_ips.py | 19 |
2 files changed, 119 insertions, 4 deletions
diff --git a/nova/api/openstack/v2/contrib/floating_ip_pools.py b/nova/api/openstack/v2/contrib/floating_ip_pools.py new file mode 100644 index 000000000..9d6386f25 --- /dev/null +++ b/nova/api/openstack/v2/contrib/floating_ip_pools.py @@ -0,0 +1,104 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2011 X.commerce, a business unit of eBay Inc. +# +# 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 wsgi +from nova.api.openstack import xmlutil +from nova.api.openstack.v2 import extensions +from nova import log as logging +from nova import network + + +LOG = logging.getLogger('nova.api.openstack.v2.contrib.floating_ip_poolss') + + +def _translate_floating_ip_view(pool): + return { + 'name': pool['name'], + } + + +def _translate_floating_ip_pools_view(pools): + return { + 'floating_ip_pools': [_translate_floating_ip_view(pool) + for pool in pools] + } + + +class FloatingIPPoolsController(object): + """The Floating IP Pool API controller for the OpenStack API.""" + + def __init__(self): + self.network_api = network.API() + super(FloatingIPPoolsController, self).__init__() + + def index(self, req): + """Return a list of pools.""" + context = req.environ['nova.context'] + pools = self.network_api.get_floating_ip_pools(context) + return _translate_floating_ip_pools_view(pools) + + +def make_float_ip(elem): + elem.set('name') + + +class FloatingIPPoolTemplate(xmlutil.TemplateBuilder): + def construct(self): + root = xmlutil.TemplateElement('floating_ip_pool', + selector='floating_ip_pool') + make_float_ip(root) + return xmlutil.MasterTemplate(root, 1) + + +class FloatingIPPoolsTemplate(xmlutil.TemplateBuilder): + def construct(self): + root = xmlutil.TemplateElement('floating_ip_pools') + elem = xmlutil.SubTemplateElement(root, 'floating_ip_pool', + selector='floating_ip_pools') + make_float_ip(elem) + return xmlutil.MasterTemplate(root, 1) + + +class FloatingIPPoolsSerializer(xmlutil.XMLTemplateSerializer): + def index(self): + return FloatingIPPoolsTemplate() + + +class Floating_ip_pools(extensions.ExtensionDescriptor): + """Floating IPs support""" + + name = "Floating_ip_pools" + alias = "os-floating-ip-pools" + namespace = \ + "http://docs.openstack.org/compute/ext/floating_ip_pools/api/v1.1" + updated = "2012-01-04T00:00:00+00:00" + + def get_resources(self): + resources = [] + + body_serializers = { + 'application/xml': FloatingIPPoolsSerializer(), + } + + serializer = wsgi.ResponseSerializer(body_serializers) + + res = extensions.ResourceExtension('os-floating-ip-pools', + FloatingIPPoolsController(), + serializer=serializer, + member_actions={}) + resources.append(res) + + return resources diff --git a/nova/api/openstack/v2/contrib/floating_ips.py b/nova/api/openstack/v2/contrib/floating_ips.py index 39700d382..3a6f4ee34 100644 --- a/nova/api/openstack/v2/contrib/floating_ips.py +++ b/nova/api/openstack/v2/contrib/floating_ips.py @@ -1,6 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2011 OpenStack LLC. +# Copyright (c) 2011 X.commerce, a business unit of eBay Inc. # Copyright 2011 Grid Dynamics # Copyright 2011 Eldar Nugaev, Kirill Shileev, Ilya Alekseyev # @@ -34,6 +35,7 @@ LOG = logging.getLogger('nova.api.openstack.v2.contrib.floating_ips') def make_float_ip(elem): elem.set('id') elem.set('ip') + elem.set('pool') elem.set('fixed_ip') elem.set('instance_id') @@ -56,8 +58,11 @@ class FloatingIPsTemplate(xmlutil.TemplateBuilder): def _translate_floating_ip_view(floating_ip): - result = {'id': floating_ip['id'], - 'ip': floating_ip['address']} + result = { + 'id': floating_ip['id'], + 'ip': floating_ip['address'], + 'pool': floating_ip['pool'], + } try: result['fixed_ip'] = floating_ip['fixed_ip']['address'] except (TypeError, KeyError): @@ -106,13 +111,19 @@ class FloatingIPController(object): def create(self, req, body=None): context = req.environ['nova.context'] + pool = None + if body and 'pool' in body: + pool = body['pool'] try: - address = self.network_api.allocate_floating_ip(context) + address = self.network_api.allocate_floating_ip(context, pool) ip = self.network_api.get_floating_ip_by_address(context, address) except rpc.RemoteError as ex: # NOTE(tr3buchet) - why does this block exist? if ex.exc_type == 'NoMoreFloatingIps': - msg = _("No more floating ips available.") + if pool: + msg = _("No more floating ips in pool %s.") % pool + else: + msg = _("No more floating ips available.") raise webob.exc.HTTPBadRequest(explanation=msg) else: raise |
