Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 1 | # 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 | |
| 16 | from oslo_serialization import jsonutils as json |
| 17 | |
| 18 | from tempest.lib.api_schema.response.compute.v2_1 import quotas as schema |
| 19 | from tempest.lib.common import rest_client |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 20 | from tempest.lib.services.compute import base_compute_client |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 21 | |
| 22 | |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 23 | class QuotasClient(base_compute_client.BaseComputeClient): |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 24 | |
| 25 | def show_quota_set(self, tenant_id, user_id=None): |
| 26 | """List the quota set for a tenant.""" |
| 27 | |
| 28 | url = 'os-quota-sets/%s' % tenant_id |
| 29 | if user_id: |
| 30 | url += '?user_id=%s' % user_id |
| 31 | resp, body = self.get(url) |
| 32 | body = json.loads(body) |
| 33 | self.validate_response(schema.get_quota_set, resp, body) |
| 34 | return rest_client.ResponseBody(resp, body) |
| 35 | |
| 36 | def show_default_quota_set(self, tenant_id): |
| 37 | """List the default quota set for a tenant.""" |
| 38 | |
| 39 | url = 'os-quota-sets/%s/defaults' % tenant_id |
| 40 | resp, body = self.get(url) |
| 41 | body = json.loads(body) |
| 42 | self.validate_response(schema.get_quota_set, resp, body) |
| 43 | return rest_client.ResponseBody(resp, body) |
| 44 | |
| 45 | def update_quota_set(self, tenant_id, user_id=None, **kwargs): |
| 46 | """Updates the tenant's quota limits for one or more resources. |
| 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: |
zhufl | 126a66d | 2017-03-08 15:32:21 +0800 | [diff] [blame] | 50 | https://developer.openstack.org/api-ref/compute/#update-quotas |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 51 | """ |
| 52 | |
| 53 | post_body = json.dumps({'quota_set': kwargs}) |
| 54 | |
| 55 | if user_id: |
| 56 | resp, body = self.put('os-quota-sets/%s?user_id=%s' % |
| 57 | (tenant_id, user_id), post_body) |
| 58 | else: |
| 59 | resp, body = self.put('os-quota-sets/%s' % tenant_id, |
| 60 | post_body) |
| 61 | |
| 62 | body = json.loads(body) |
| 63 | self.validate_response(schema.update_quota_set, resp, body) |
| 64 | return rest_client.ResponseBody(resp, body) |
| 65 | |
| 66 | def delete_quota_set(self, tenant_id): |
| 67 | """Delete the tenant's quota set.""" |
| 68 | resp, body = self.delete('os-quota-sets/%s' % tenant_id) |
| 69 | self.validate_response(schema.delete_quota, resp, body) |
| 70 | return rest_client.ResponseBody(resp, body) |