blob: 265969a00586fcdad1155a1ec06053d123f965b3 [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 import quotas as schema
19from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090020from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050021
22
Ghanshyamee9af302016-02-25 06:12:43 +090023class QuotasClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050024
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, Yuanyingfaac5712016-09-15 13:53:55 +090048 For a full list of available parameters, please refer to the official
49 API reference:
zhufl126a66d2017-03-08 15:32:21 +080050 https://developer.openstack.org/api-ref/compute/#update-quotas
Matthew Treinish9e26ca82016-02-23 11:43:20 -050051 """
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)