~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/api/openstack/v2/contrib/floating_ip_pools.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandleman
  • Date: 2012-01-13 09:51:10 UTC
  • mfrom: (1.1.40)
  • Revision ID: package-import@ubuntu.com-20120113095110-ffd6163drcg77wez
Tags: 2012.1~e3~20120113.12049-0ubuntu1
[Chuck Short]
* New upstream version.
* debian/nova_sudoers, debian/nova-common.install, 
  Switch out to nova-rootwrap. (LP: #681774)
* Add "get-origsource-git" which allows developers to 
  generate a tarball from github, by doing:
  fakeroot debian/rules get-orig-source-git
* debian/debian/nova-objectstore.logrotate: Dont determine
  if we are running Debian or Ubuntu. (LP: #91379)

[Adam Gandleman]
* Removed python-nova.postinst, let dh_python2 generate instead since
  python-support is not a dependency. (LP: #907543)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
 
4
#
 
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
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
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
 
15
#    under the License
 
16
 
 
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
 
22
 
 
23
 
 
24
LOG = logging.getLogger('nova.api.openstack.v2.contrib.floating_ip_poolss')
 
25
 
 
26
 
 
27
def _translate_floating_ip_view(pool):
 
28
    return {
 
29
        'name': pool['name'],
 
30
    }
 
31
 
 
32
 
 
33
def _translate_floating_ip_pools_view(pools):
 
34
    return {
 
35
        'floating_ip_pools': [_translate_floating_ip_view(pool)
 
36
                              for pool in pools]
 
37
    }
 
38
 
 
39
 
 
40
class FloatingIPPoolsController(object):
 
41
    """The Floating IP Pool API controller for the OpenStack API."""
 
42
 
 
43
    def __init__(self):
 
44
        self.network_api = network.API()
 
45
        super(FloatingIPPoolsController, self).__init__()
 
46
 
 
47
    def index(self, req):
 
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)
 
52
 
 
53
 
 
54
def make_float_ip(elem):
 
55
    elem.set('name')
 
56
 
 
57
 
 
58
class FloatingIPPoolTemplate(xmlutil.TemplateBuilder):
 
59
    def construct(self):
 
60
        root = xmlutil.TemplateElement('floating_ip_pool',
 
61
                                       selector='floating_ip_pool')
 
62
        make_float_ip(root)
 
63
        return xmlutil.MasterTemplate(root, 1)
 
64
 
 
65
 
 
66
class FloatingIPPoolsTemplate(xmlutil.TemplateBuilder):
 
67
    def construct(self):
 
68
        root = xmlutil.TemplateElement('floating_ip_pools')
 
69
        elem = xmlutil.SubTemplateElement(root, 'floating_ip_pool',
 
70
                                          selector='floating_ip_pools')
 
71
        make_float_ip(elem)
 
72
        return xmlutil.MasterTemplate(root, 1)
 
73
 
 
74
 
 
75
class FloatingIPPoolsSerializer(xmlutil.XMLTemplateSerializer):
 
76
    def index(self):
 
77
        return FloatingIPPoolsTemplate()
 
78
 
 
79
 
 
80
class Floating_ip_pools(extensions.ExtensionDescriptor):
 
81
    """Floating IPs support"""
 
82
 
 
83
    name = "Floating_ip_pools"
 
84
    alias = "os-floating-ip-pools"
 
85
    namespace = \
 
86
        "http://docs.openstack.org/compute/ext/floating_ip_pools/api/v1.1"
 
87
    updated = "2012-01-04T00:00:00+00:00"
 
88
 
 
89
    def get_resources(self):
 
90
        resources = []
 
91
 
 
92
        body_serializers = {
 
93
            'application/xml': FloatingIPPoolsSerializer(),
 
94
            }
 
95
 
 
96
        serializer = wsgi.ResponseSerializer(body_serializers)
 
97
 
 
98
        res = extensions.ResourceExtension('os-floating-ip-pools',
 
99
                         FloatingIPPoolsController(),
 
100
                         serializer=serializer,
 
101
                         member_actions={})
 
102
        resources.append(res)
 
103
 
 
104
        return resources