blob: 12df89528c028bba800e3e99e5bf16607b1e39c6 [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
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050017from six.moves.urllib import parse as urllib
Matthew Treinish9e26ca82016-02-23 11:43:20 -050018
19from tempest.lib.api_schema.response.compute.v2_1 import quotas as schema
20from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090021from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050022
23
Ghanshyamee9af302016-02-25 06:12:43 +090024class QuotasClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050025
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050026 def show_quota_set(self, tenant_id, user_id=None, detail=False):
27 """List the quota set for a tenant.
Matthew Treinish9e26ca82016-02-23 11:43:20 -050028
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050029 For a full list of available parameters, please refer to the official
30 API reference:
deepak_mouryafb0b7082018-01-23 17:00:27 +053031 https://developer.openstack.org/api-ref/compute/#show-a-quota
32 https://developer.openstack.org/api-ref/compute/#show-the-detail-of-quota
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050033 """
34
35 params = {}
Matthew Treinish9e26ca82016-02-23 11:43:20 -050036 url = 'os-quota-sets/%s' % tenant_id
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050037 if detail:
38 url += '/detail'
Matthew Treinish9e26ca82016-02-23 11:43:20 -050039 if user_id:
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050040 params.update({'user_id': user_id})
41 if params:
42 url += '?%s' % urllib.urlencode(params)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050043 resp, body = self.get(url)
44 body = json.loads(body)
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050045 if detail:
46 self.validate_response(schema.get_quota_set_details, resp, body)
47 else:
48 self.validate_response(schema.get_quota_set, resp, body)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050049 return rest_client.ResponseBody(resp, body)
50
51 def show_default_quota_set(self, tenant_id):
deepak_mouryafb0b7082018-01-23 17:00:27 +053052 """List the default quota set for a tenant.
53
54 https://developer.openstack.org/api-ref/compute/#list-default-quotas-for-tenant
55 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -050056
57 url = 'os-quota-sets/%s/defaults' % tenant_id
58 resp, body = self.get(url)
59 body = json.loads(body)
60 self.validate_response(schema.get_quota_set, resp, body)
61 return rest_client.ResponseBody(resp, body)
62
63 def update_quota_set(self, tenant_id, user_id=None, **kwargs):
64 """Updates the tenant's quota limits for one or more resources.
65
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090066 For a full list of available parameters, please refer to the official
67 API reference:
zhufl126a66d2017-03-08 15:32:21 +080068 https://developer.openstack.org/api-ref/compute/#update-quotas
Matthew Treinish9e26ca82016-02-23 11:43:20 -050069 """
70
71 post_body = json.dumps({'quota_set': kwargs})
72
73 if user_id:
74 resp, body = self.put('os-quota-sets/%s?user_id=%s' %
75 (tenant_id, user_id), post_body)
76 else:
77 resp, body = self.put('os-quota-sets/%s' % tenant_id,
78 post_body)
79
80 body = json.loads(body)
81 self.validate_response(schema.update_quota_set, resp, body)
82 return rest_client.ResponseBody(resp, body)
83
84 def delete_quota_set(self, tenant_id):
deepak_mouryafb0b7082018-01-23 17:00:27 +053085 """Delete the tenant's quota set.
86
87 https://developer.openstack.org/api-ref/compute/#revert-quotas-to-defaults
88 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -050089 resp, body = self.delete('os-quota-sets/%s' % tenant_id)
90 self.validate_response(schema.delete_quota, resp, body)
91 return rest_client.ResponseBody(resp, body)