Coverage for manila/api/v2/quota_class_sets.py: 100%
76 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2012 OpenStack LLC.
2# Copyright (c) 2015 Mirantis inc.
3# All Rights Reserved.
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.
17import webob
19from manila.api.openstack import wsgi
20from manila.api.schemas import quota_class_sets as schema
21from manila.api import validation
22from manila.api.views import quota_class_sets as quota_class_sets_views
23from manila import db
24from manila import exception
25from manila import quota
27QUOTAS = quota.QUOTAS
30class QuotaClassSetsMixin(object):
31 """The Quota Class Sets API controller common logic.
33 Mixin class that should be inherited by Quota Class Sets API controllers,
34 which are used for different API URLs and microversions.
35 """
37 resource_name = "quota_class_set"
38 _view_builder_class = quota_class_sets_views.ViewBuilder
40 @wsgi.Controller.authorize("show")
41 def _show(self, req, id):
42 context = req.environ['manila.context']
43 try:
44 db.authorize_quota_class_context(context, id)
45 except exception.NotAuthorized:
46 raise webob.exc.HTTPForbidden()
48 return self._view_builder.detail_list(
49 req, QUOTAS.get_class_quotas(context, id), id
50 )
52 @wsgi.Controller.authorize("update")
53 def _update(self, req, id, body):
54 context = req.environ['manila.context']
55 quota_class = id
56 for key in body.get(self.resource_name, {}).keys():
57 if key in QUOTAS:
58 value = int(body[self.resource_name][key])
59 try:
60 db.quota_class_update(context, quota_class, key, value)
61 except exception.QuotaClassNotFound:
62 db.quota_class_create(context, quota_class, key, value)
63 except exception.AdminRequired:
64 raise webob.exc.HTTPForbidden()
65 return self._view_builder.detail_list(
66 req, QUOTAS.get_class_quotas(context, quota_class)
67 )
70@validation.validated
71class QuotaClassSetsControllerLegacy(QuotaClassSetsMixin, wsgi.Controller):
72 """Deprecated Quota Class Sets API controller.
74 Use microversions 2.0 to 2.6. Registered under deprecated API URL
75 'os-quota-class-sets'.
76 """
78 @wsgi.Controller.api_version('1.0', '2.6')
79 @validation.request_query_schema(schema.show_request_query)
80 @validation.response_body_schema(schema.show_response_body)
81 def show(self, req, id):
82 return self._show(req, id)
84 @wsgi.Controller.api_version('1.0', '2.6')
85 @validation.request_body_schema(schema.update_request_body)
86 @validation.response_body_schema(schema.update_response_body)
87 def update(self, req, id, body):
88 return self._update(req, id, body)
91@validation.validated
92class QuotaClassSetsController(QuotaClassSetsMixin, wsgi.Controller):
93 """Quota Class Sets API controller.
95 Used from microversion 2.7. Registered under API URL 'quota-class-sets'.
96 """
98 @wsgi.Controller.api_version('2.7')
99 @validation.request_query_schema(schema.show_request_query, '2.7')
100 @validation.response_body_schema(
101 schema.show_response_body, '1.0', '2.39')
102 @validation.response_body_schema(
103 schema.show_response_body_v240, '2.40', '2.52')
104 @validation.response_body_schema(
105 schema.show_response_body_v253, '2.53', '2.61')
106 @validation.response_body_schema(
107 schema.show_response_body_v262, '2.62', '2.79')
108 @validation.response_body_schema(
109 schema.show_response_body_v280, '2.80', '2.89')
110 @validation.response_body_schema(schema.show_response_body_v290, '2.90')
111 def show(self, req, id):
112 return self._show(req, id)
114 @wsgi.Controller.api_version('2.7')
115 @validation.request_body_schema(
116 schema.update_request_body, '2.7', '2.52')
117 @validation.request_body_schema(
118 schema.update_request_body_v253, '2.53', '2.61')
119 @validation.request_body_schema(
120 schema.update_request_body_v262, '2.62', '2.79')
121 @validation.request_body_schema(
122 schema.update_request_body_v280, '2.80', '2.89')
123 @validation.request_body_schema(schema.update_request_body_v290, '2.90')
124 @validation.response_body_schema(
125 schema.update_response_body, '2.7', '2.39')
126 @validation.response_body_schema(
127 schema.update_response_body_v240, '2.40', '2.52')
128 @validation.response_body_schema(
129 schema.update_response_body_v253, '2.53', '2.61')
130 @validation.response_body_schema(
131 schema.update_response_body_v262, '2.62', '2.79')
132 @validation.response_body_schema(
133 schema.update_response_body_v280, '2.80', '2.89')
134 @validation.response_body_schema(schema.update_response_body_v290, '2.90')
135 def update(self, req, id, body):
136 return self._update(req, id, body)
139def create_resource_legacy():
140 return wsgi.Resource(QuotaClassSetsControllerLegacy())
143def create_resource():
144 return wsgi.Resource(QuotaClassSetsController())