blob: 7f191ca765698d85c4dcb0bd81b59f6805b57d6f [file] [log] [blame]
Yaroslav Lobankovdb4a2e12015-11-28 20:04:54 +03001# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Ken'ichi Ohmichif66afb82016-08-05 14:47:16 -070015from oslo_serialization import jsonutils
16from six.moves.urllib import parse as urllib
17
18from tempest.lib.common import rest_client
Yaroslav Lobankovdb4a2e12015-11-28 20:04:54 +030019
20
Ken'ichi Ohmichif66afb82016-08-05 14:47:16 -070021class QuotasClient(rest_client.RestClient):
22 """Client class to send CRUD Volume Quotas API V1 requests"""
23
24 def show_default_quota_set(self, tenant_id):
25 """List the default volume quota set for a tenant."""
26
27 url = 'os-quota-sets/%s/defaults' % tenant_id
28 resp, body = self.get(url)
29 self.expected_success(200, resp.status)
30 body = jsonutils.loads(body)
31 return rest_client.ResponseBody(resp, body)
32
33 def show_quota_set(self, tenant_id, params=None):
34 """List the quota set for a tenant."""
35
36 url = 'os-quota-sets/%s' % tenant_id
37 if params:
38 url += '?%s' % urllib.urlencode(params)
39
40 resp, body = self.get(url)
41 self.expected_success(200, resp.status)
42 body = jsonutils.loads(body)
43 return rest_client.ResponseBody(resp, body)
44
45 def update_quota_set(self, tenant_id, **kwargs):
46 """Updates quota set
47
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090048 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/block-storage/v2/#update-quotas
Ken'ichi Ohmichif66afb82016-08-05 14:47:16 -070051 """
52 put_body = jsonutils.dumps({'quota_set': kwargs})
53 resp, body = self.put('os-quota-sets/%s' % tenant_id, put_body)
54 self.expected_success(200, resp.status)
55 body = jsonutils.loads(body)
56 return rest_client.ResponseBody(resp, body)
57
58 def delete_quota_set(self, tenant_id):
59 """Delete the tenant's quota set."""
60 resp, body = self.delete('os-quota-sets/%s' % tenant_id)
61 self.expected_success(200, resp.status)
62 return rest_client.ResponseBody(resp, body)