blob: 5f220a72d153a4b20b69a9ac09a42159d307b01f [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# Copyright 2012 NTT Data
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from oslo_serialization import jsonutils as json
17
18from tempest.lib.api_schema.response.compute.v2_1\
Ghanshyam Manndc517e02021-12-16 15:36:31 -060019 import quota_classes as schema
20from tempest.lib.api_schema.response.compute.v2_50 import quota_classes \
21 as schemav250
22from tempest.lib.api_schema.response.compute.v2_57 import quota_classes \
23 as schemav257
Matthew Treinish9e26ca82016-02-23 11:43:20 -050024from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090025from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050026
27
Ghanshyamee9af302016-02-25 06:12:43 +090028class QuotaClassesClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050029
Ghanshyam Manndc517e02021-12-16 15:36:31 -060030 schema_versions_info = [
31 {'min': None, 'max': '2.49', 'schema': schema},
32 {'min': '2.50', 'max': '2.56', 'schema': schemav250},
33 {'min': '2.57', 'max': None, 'schema': schemav257}]
34
Matthew Treinish9e26ca82016-02-23 11:43:20 -050035 def show_quota_class_set(self, quota_class_id):
36 """List the quota class set for a quota class."""
37
38 url = 'os-quota-class-sets/%s' % quota_class_id
39 resp, body = self.get(url)
40 body = json.loads(body)
Ghanshyam Manndc517e02021-12-16 15:36:31 -060041 _schema = self.get_schema(self.schema_versions_info)
42 self.validate_response(_schema.get_quota_class_set, resp, body)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050043 return rest_client.ResponseBody(resp, body)
44
45 def update_quota_class_set(self, quota_class_id, **kwargs):
46 """Update the quota class's limits for one or more resources.
47
kkush09a66e62018-01-29 19:00:15 +053048 For a full list of available parameters, please refer to the official
49 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020050 https://docs.openstack.org/api-ref/compute/#create-or-update-quotas-for-quota-class
Matthew Treinish9e26ca82016-02-23 11:43:20 -050051 """
52 post_body = json.dumps({'quota_class_set': kwargs})
53
54 resp, body = self.put('os-quota-class-sets/%s' % quota_class_id,
55 post_body)
56
57 body = json.loads(body)
Ghanshyam Manndc517e02021-12-16 15:36:31 -060058 _schema = self.get_schema(self.schema_versions_info)
59 self.validate_response(_schema.update_quota_class_set,
Matthew Treinish9e26ca82016-02-23 11:43:20 -050060 resp, body)
61 return rest_client.ResponseBody(resp, body)