blob: 3839c74b5ff2ce6a97d77f3ae080b2887b55a1e0 [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:
31 http://developer.openstack.org/api-ref-compute-v2.1.html/#show-a-quota
32 http://developer.openstack.org/api-ref-compute-v2.1.html/#show-the-detail-of-quota
33 """
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):
52 """List the default quota set for a tenant."""
53
54 url = 'os-quota-sets/%s/defaults' % tenant_id
55 resp, body = self.get(url)
56 body = json.loads(body)
57 self.validate_response(schema.get_quota_set, resp, body)
58 return rest_client.ResponseBody(resp, body)
59
60 def update_quota_set(self, tenant_id, user_id=None, **kwargs):
61 """Updates the tenant's quota limits for one or more resources.
62
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090063 For a full list of available parameters, please refer to the official
64 API reference:
65 http://developer.openstack.org/api-ref-compute-v2.1.html#updateQuota
Matthew Treinish9e26ca82016-02-23 11:43:20 -050066 """
67
68 post_body = json.dumps({'quota_set': kwargs})
69
70 if user_id:
71 resp, body = self.put('os-quota-sets/%s?user_id=%s' %
72 (tenant_id, user_id), post_body)
73 else:
74 resp, body = self.put('os-quota-sets/%s' % tenant_id,
75 post_body)
76
77 body = json.loads(body)
78 self.validate_response(schema.update_quota_set, resp, body)
79 return rest_client.ResponseBody(resp, body)
80
81 def delete_quota_set(self, tenant_id):
82 """Delete the tenant's quota set."""
83 resp, body = self.delete('os-quota-sets/%s' % tenant_id)
84 self.validate_response(schema.delete_quota, resp, body)
85 return rest_client.ResponseBody(resp, body)