Chandan Kumar | 65eb859 | 2014-11-12 18:32:32 +0530 | [diff] [blame] | 1 | # Copyright 2014 OpenStack Foundation |
| 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 | |
Ken'ichi Ohmichi | f66afb8 | 2016-08-05 14:47:16 -0700 | [diff] [blame] | 16 | from oslo_serialization import jsonutils |
| 17 | from six.moves.urllib import parse as urllib |
| 18 | |
| 19 | from tempest.lib.common import rest_client |
Chandan Kumar | 65eb859 | 2014-11-12 18:32:32 +0530 | [diff] [blame] | 20 | |
| 21 | |
Ken'ichi Ohmichi | f66afb8 | 2016-08-05 14:47:16 -0700 | [diff] [blame] | 22 | class QuotasClient(rest_client.RestClient): |
| 23 | """Client class to send CRUD Volume Quotas API V2 requests""" |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 24 | api_version = "v2" |
Ken'ichi Ohmichi | f66afb8 | 2016-08-05 14:47:16 -0700 | [diff] [blame] | 25 | |
| 26 | def show_default_quota_set(self, tenant_id): |
| 27 | """List the default volume quota set for a tenant.""" |
| 28 | |
| 29 | url = 'os-quota-sets/%s/defaults' % tenant_id |
| 30 | resp, body = self.get(url) |
| 31 | self.expected_success(200, resp.status) |
| 32 | body = jsonutils.loads(body) |
| 33 | return rest_client.ResponseBody(resp, body) |
| 34 | |
| 35 | def show_quota_set(self, tenant_id, params=None): |
| 36 | """List the quota set for a tenant.""" |
| 37 | |
| 38 | url = 'os-quota-sets/%s' % tenant_id |
| 39 | if params: |
| 40 | url += '?%s' % urllib.urlencode(params) |
| 41 | |
| 42 | resp, body = self.get(url) |
| 43 | self.expected_success(200, resp.status) |
| 44 | body = jsonutils.loads(body) |
| 45 | return rest_client.ResponseBody(resp, body) |
| 46 | |
| 47 | def update_quota_set(self, tenant_id, **kwargs): |
| 48 | """Updates quota set |
| 49 | |
| 50 | Available params: see http://developer.openstack.org/ |
| 51 | api-ref-blockstorage-v2.html#updateQuotas-v2 |
| 52 | """ |
| 53 | put_body = jsonutils.dumps({'quota_set': kwargs}) |
| 54 | resp, body = self.put('os-quota-sets/%s' % tenant_id, put_body) |
| 55 | self.expected_success(200, resp.status) |
| 56 | body = jsonutils.loads(body) |
| 57 | return rest_client.ResponseBody(resp, body) |
| 58 | |
| 59 | def delete_quota_set(self, tenant_id): |
| 60 | """Delete the tenant's quota set.""" |
| 61 | resp, body = self.delete('os-quota-sets/%s' % tenant_id) |
| 62 | self.expected_success(200, resp.status) |
| 63 | return rest_client.ResponseBody(resp, body) |