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 types manage extension."""
22
from nova.api.openstack import extensions
23
from nova.api.openstack.volume import types
24
from nova.api.openstack.volume.views import types as views_types
25
from nova.api.openstack import wsgi
26
from nova import exception
27
from nova.volume import volume_types
30
authorize = extensions.extension_authorizer('volume', 'types_manage')
33
class VolumeTypesManageController(wsgi.Controller):
34
""" The volume types API controller for the OpenStack API """
36
_view_builder_class = views_types.ViewBuilder
38
@wsgi.action("create")
39
@wsgi.serializers(xml=types.VolumeTypeTemplate)
40
def _create(self, req, body):
41
"""Creates a new volume type."""
42
context = req.environ['nova.context']
45
if not self.is_valid_body(body, 'volume_type'):
46
raise webob.exc.HTTPUnprocessableEntity()
48
vol_type = body['volume_type']
49
name = vol_type.get('name', None)
50
specs = vol_type.get('extra_specs', {})
52
if name is None or name == "":
53
raise webob.exc.HTTPUnprocessableEntity()
56
volume_types.create(context, name, specs)
57
vol_type = volume_types.get_volume_type_by_name(context, name)
58
except exception.VolumeTypeExists as err:
59
raise webob.exc.HTTPConflict(explanation=str(err))
60
except exception.NotFound:
61
raise webob.exc.HTTPNotFound()
63
return self._view_builder.show(req, vol_type)
65
@wsgi.action("delete")
66
def _delete(self, req, id):
67
""" Deletes an existing volume type """
68
context = req.environ['nova.context']
72
vol_type = volume_types.get_volume_type(context, id)
73
volume_types.destroy(context, vol_type['name'])
74
except exception.NotFound:
75
raise webob.exc.HTTPNotFound()
77
return webob.Response(status_int=202)
80
class Types_manage(extensions.ExtensionDescriptor):
81
"""Types manage support"""
84
alias = "os-types-manage"
85
namespace = "http://docs.openstack.org/volume/ext/types-manage/api/v1"
86
updated = "2011-08-24T00:00:00+00:00"
88
def get_controller_extensions(self):
89
controller = VolumeTypesManageController()
90
extension = extensions.ControllerExtension(self, 'types', controller)