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

« back to all changes in this revision

Viewing changes to cinder/api/v1/types.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-11-23 08:39:28 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20121123083928-xvzet603cjfj9p1t
Tags: 2013.1~g1-0ubuntu1
* New upstream release.
* debian/patches/avoid_setuptools_git_dependency.patch:
  Avoid git installation. (LP: #1075948) 

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 Zadara Storage Inc.
 
4
# Copyright (c) 2011 OpenStack LLC.
 
5
#
 
6
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
7
#    not use this file except in compliance with the License. You may obtain
 
8
#    a copy of the License at
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
#    Unless required by applicable law or agreed to in writing, software
 
13
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
15
#    License for the specific language governing permissions and limitations
 
16
#    under the License.
 
17
 
 
18
""" The volume type & volume types extra specs extension"""
 
19
 
 
20
from webob import exc
 
21
 
 
22
from cinder.api.openstack import wsgi
 
23
from cinder.api.views import types as views_types
 
24
from cinder.api import xmlutil
 
25
from cinder import exception
 
26
from cinder.volume import volume_types
 
27
 
 
28
 
 
29
def make_voltype(elem):
 
30
    elem.set('id')
 
31
    elem.set('name')
 
32
    extra_specs = xmlutil.make_flat_dict('extra_specs', selector='extra_specs')
 
33
    elem.append(extra_specs)
 
34
 
 
35
 
 
36
class VolumeTypeTemplate(xmlutil.TemplateBuilder):
 
37
    def construct(self):
 
38
        root = xmlutil.TemplateElement('volume_type', selector='volume_type')
 
39
        make_voltype(root)
 
40
        return xmlutil.MasterTemplate(root, 1)
 
41
 
 
42
 
 
43
class VolumeTypesTemplate(xmlutil.TemplateBuilder):
 
44
    def construct(self):
 
45
        root = xmlutil.TemplateElement('volume_types')
 
46
        elem = xmlutil.SubTemplateElement(root, 'volume_type',
 
47
                                          selector='volume_types')
 
48
        make_voltype(elem)
 
49
        return xmlutil.MasterTemplate(root, 1)
 
50
 
 
51
 
 
52
class VolumeTypesController(wsgi.Controller):
 
53
    """ The volume types API controller for the OpenStack API """
 
54
 
 
55
    _view_builder_class = views_types.ViewBuilder
 
56
 
 
57
    @wsgi.serializers(xml=VolumeTypesTemplate)
 
58
    def index(self, req):
 
59
        """ Returns the list of volume types """
 
60
        context = req.environ['cinder.context']
 
61
        vol_types = volume_types.get_all_types(context).values()
 
62
        return self._view_builder.index(req, vol_types)
 
63
 
 
64
    @wsgi.serializers(xml=VolumeTypeTemplate)
 
65
    def show(self, req, id):
 
66
        """ Return a single volume type item """
 
67
        context = req.environ['cinder.context']
 
68
 
 
69
        try:
 
70
            vol_type = volume_types.get_volume_type(context, id)
 
71
        except exception.NotFound:
 
72
            raise exc.HTTPNotFound()
 
73
 
 
74
        # TODO(bcwaldon): remove str cast once we use uuids
 
75
        vol_type['id'] = str(vol_type['id'])
 
76
        return self._view_builder.show(req, vol_type)
 
77
 
 
78
 
 
79
def create_resource():
 
80
    return wsgi.Resource(VolumeTypesController())