Yaroslav Lobankov | db4a2e1 | 2015-11-28 20:04:54 +0300 | [diff] [blame] | 1 | # 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 Ohmichi | f66afb8 | 2016-08-05 14:47:16 -0700 | [diff] [blame] | 15 | from oslo_serialization import jsonutils |
| 16 | from six.moves.urllib import parse as urllib |
| 17 | |
| 18 | from tempest.lib.common import rest_client |
Yaroslav Lobankov | db4a2e1 | 2015-11-28 20:04:54 +0300 | [diff] [blame] | 19 | |
| 20 | |
Ken'ichi Ohmichi | f66afb8 | 2016-08-05 14:47:16 -0700 | [diff] [blame] | 21 | class 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, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 48 | For a full list of available parameters, please refer to the official |
| 49 | API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 50 | https://docs.openstack.org/api-ref/block-storage/v2/#update-quotas |
Ken'ichi Ohmichi | f66afb8 | 2016-08-05 14:47:16 -0700 | [diff] [blame] | 51 | """ |
| 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) |