~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to nova/api/openstack/compute/contrib/flavor_disabled.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Soren Hansen
  • Date: 2012-09-07 17:49:53 UTC
  • mfrom: (1.1.61)
  • Revision ID: package-import@ubuntu.com-20120907174953-oapuvix1jxm830he
Tags: 2012.2~rc1~20120907.15996-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/nova-common.postinst: Drop nova_sudoers permission changing
  since we do it in the debian/rules. (LP: #995285)

[ Soren Hansen ]
* Update debian/watch to account for symbolically named tarballs and
  use newer URL.
* Fix Launchpad URLs in debian/watch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#   Copyright 2012 Nebula, Inc.
 
2
#
 
3
#   Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
#   not use this file except in compliance with the License. You may obtain
 
5
#   a copy of the License at
 
6
#
 
7
#       http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
#   Unless required by applicable law or agreed to in writing, software
 
10
#   distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
#   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
#   License for the specific language governing permissions and limitations
 
13
#   under the License.
 
14
 
 
15
"""The Flavor Disabled API extension."""
 
16
 
 
17
from nova.api.openstack import extensions
 
18
from nova.api.openstack import wsgi
 
19
from nova.api.openstack import xmlutil
 
20
 
 
21
 
 
22
authorize = extensions.soft_extension_authorizer('compute', 'flavor_disabled')
 
23
 
 
24
 
 
25
class FlavorDisabledController(wsgi.Controller):
 
26
    def _extend_flavors(self, req, flavors):
 
27
        for flavor in flavors:
 
28
            db_flavor = req.get_db_flavor(flavor['id'])
 
29
            key = "%s:disabled" % Flavor_disabled.alias
 
30
            flavor[key] = db_flavor['disabled']
 
31
 
 
32
    def _show(self, req, resp_obj):
 
33
        if not authorize(req.environ['nova.context']):
 
34
            return
 
35
        if 'flavor' in resp_obj.obj:
 
36
            resp_obj.attach(xml=FlavorDisabledTemplate())
 
37
            self._extend_flavors(req, [resp_obj.obj['flavor']])
 
38
 
 
39
    @wsgi.extends
 
40
    def show(self, req, resp_obj, id):
 
41
        return self._show(req, resp_obj)
 
42
 
 
43
    @wsgi.extends(action='create')
 
44
    def create(self, req, resp_obj, body):
 
45
        return self._show(req, resp_obj)
 
46
 
 
47
    @wsgi.extends
 
48
    def detail(self, req, resp_obj):
 
49
        if not authorize(req.environ['nova.context']):
 
50
            return
 
51
        resp_obj.attach(xml=FlavorsDisabledTemplate())
 
52
        self._extend_flavors(req, list(resp_obj.obj['flavors']))
 
53
 
 
54
 
 
55
class Flavor_disabled(extensions.ExtensionDescriptor):
 
56
    """Support to show the disabled status of a flavor"""
 
57
 
 
58
    name = "FlavorDisabled"
 
59
    alias = "OS-FLV-DISABLED"
 
60
    namespace = ("http://docs.openstack.org/compute/ext/"
 
61
                 "flavor_disabled/api/v1.1")
 
62
    updated = "2012-08-29T00:00:00+00:00"
 
63
 
 
64
    def get_controller_extensions(self):
 
65
        controller = FlavorDisabledController()
 
66
        extension = extensions.ControllerExtension(self, 'flavors', controller)
 
67
        return [extension]
 
68
 
 
69
 
 
70
def make_flavor(elem):
 
71
    elem.set('{%s}disabled' % Flavor_disabled.namespace,
 
72
             '%s:disabled' % Flavor_disabled.alias)
 
73
 
 
74
 
 
75
class FlavorDisabledTemplate(xmlutil.TemplateBuilder):
 
76
    def construct(self):
 
77
        root = xmlutil.TemplateElement('flavor', selector='flavor')
 
78
        make_flavor(root)
 
79
        return xmlutil.SlaveTemplate(root, 1, nsmap={
 
80
            Flavor_disabled.alias: Flavor_disabled.namespace})
 
81
 
 
82
 
 
83
class FlavorsDisabledTemplate(xmlutil.TemplateBuilder):
 
84
    def construct(self):
 
85
        root = xmlutil.TemplateElement('flavors')
 
86
        elem = xmlutil.SubTemplateElement(root, 'flavor', selector='flavors')
 
87
        make_flavor(elem)
 
88
        return xmlutil.SlaveTemplate(root, 1, nsmap={
 
89
            Flavor_disabled.alias: Flavor_disabled.namespace})