1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright (c) 2011 Zadara Storage Inc.
4
# Copyright (c) 2011 OpenStack LLC.
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
10
# http://www.apache.org/licenses/LICENSE-2.0
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
18
""" The volume type & volume types extra specs extension"""
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
29
def make_voltype(elem):
32
extra_specs = xmlutil.make_flat_dict('extra_specs', selector='extra_specs')
33
elem.append(extra_specs)
36
class VolumeTypeTemplate(xmlutil.TemplateBuilder):
38
root = xmlutil.TemplateElement('volume_type', selector='volume_type')
40
return xmlutil.MasterTemplate(root, 1)
43
class VolumeTypesTemplate(xmlutil.TemplateBuilder):
45
root = xmlutil.TemplateElement('volume_types')
46
elem = xmlutil.SubTemplateElement(root, 'volume_type',
47
selector='volume_types')
49
return xmlutil.MasterTemplate(root, 1)
52
class VolumeTypesController(wsgi.Controller):
53
""" The volume types API controller for the OpenStack API """
55
_view_builder_class = views_types.ViewBuilder
57
@wsgi.serializers(xml=VolumeTypesTemplate)
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)
64
@wsgi.serializers(xml=VolumeTypeTemplate)
65
def show(self, req, id):
66
""" Return a single volume type item """
67
context = req.environ['cinder.context']
70
vol_type = volume_types.get_volume_type(context, id)
71
except exception.NotFound:
72
raise exc.HTTPNotFound()
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)
79
def create_resource():
80
return wsgi.Resource(VolumeTypesController())