1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
from nova.api.openstack import wsgi
18
from nova.api.openstack import xmlutil
19
from nova.api.openstack.v2 import extensions
20
from nova import log as logging
21
from nova import network
24
LOG = logging.getLogger('nova.api.openstack.v2.contrib.floating_ip_poolss')
27
def _translate_floating_ip_view(pool):
33
def _translate_floating_ip_pools_view(pools):
35
'floating_ip_pools': [_translate_floating_ip_view(pool)
40
class FloatingIPPoolsController(object):
41
"""The Floating IP Pool API controller for the OpenStack API."""
44
self.network_api = network.API()
45
super(FloatingIPPoolsController, self).__init__()
48
"""Return a list of pools."""
49
context = req.environ['nova.context']
50
pools = self.network_api.get_floating_ip_pools(context)
51
return _translate_floating_ip_pools_view(pools)
54
def make_float_ip(elem):
58
class FloatingIPPoolTemplate(xmlutil.TemplateBuilder):
60
root = xmlutil.TemplateElement('floating_ip_pool',
61
selector='floating_ip_pool')
63
return xmlutil.MasterTemplate(root, 1)
66
class FloatingIPPoolsTemplate(xmlutil.TemplateBuilder):
68
root = xmlutil.TemplateElement('floating_ip_pools')
69
elem = xmlutil.SubTemplateElement(root, 'floating_ip_pool',
70
selector='floating_ip_pools')
72
return xmlutil.MasterTemplate(root, 1)
75
class FloatingIPPoolsSerializer(xmlutil.XMLTemplateSerializer):
77
return FloatingIPPoolsTemplate()
80
class Floating_ip_pools(extensions.ExtensionDescriptor):
81
"""Floating IPs support"""
83
name = "Floating_ip_pools"
84
alias = "os-floating-ip-pools"
86
"http://docs.openstack.org/compute/ext/floating_ip_pools/api/v1.1"
87
updated = "2012-01-04T00:00:00+00:00"
89
def get_resources(self):
93
'application/xml': FloatingIPPoolsSerializer(),
96
serializer = wsgi.ResponseSerializer(body_serializers)
98
res = extensions.ResourceExtension('os-floating-ip-pools',
99
FloatingIPPoolsController(),
100
serializer=serializer,
102
resources.append(res)