blob: aa8bfafe1d23cb4ce40a907cec78c5470778485f [file] [log] [blame]
ivan-zhu24358182013-11-27 15:08:06 +08001# 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
16import json
17
18from tempest.common.rest_client import RestClient
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
ivan-zhu24358182013-11-27 15:08:06 +080022
23
ivan-zhub6d69ee2013-12-17 14:16:31 +080024class QuotasV3ClientJSON(RestClient):
ivan-zhu24358182013-11-27 15:08:06 +080025
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000026 def __init__(self, auth_provider):
27 super(QuotasV3ClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000028 self.service = CONF.compute.catalog_v3_type
ivan-zhu24358182013-11-27 15:08:06 +080029
30 def get_quota_set(self, tenant_id):
31 """List the quota set for a tenant."""
32
33 url = 'os-quota-sets/%s' % str(tenant_id)
34 resp, body = self.get(url)
35 body = json.loads(body)
36 return resp, body['quota_set']
37
Ken'ichi Ohmichi776cda62014-02-18 21:21:23 +090038 def get_quota_set_detail(self, tenant_id):
39 """Get the quota set detail for a tenant."""
40
41 url = 'os-quota-sets/%s/detail' % str(tenant_id)
42 resp, body = self.get(url)
43 body = json.loads(body)
44 return resp, body['quota_set']
45
ivan-zhu24358182013-11-27 15:08:06 +080046 def get_default_quota_set(self, tenant_id):
47 """List the default quota set for a tenant."""
48
49 url = 'os-quota-sets/%s/defaults' % str(tenant_id)
50 resp, body = self.get(url)
51 body = json.loads(body)
52 return resp, body['quota_set']
53
54 def update_quota_set(self, tenant_id, force=None,
ivan-zhu24358182013-11-27 15:08:06 +080055 metadata_items=None, ram=None, floating_ips=None,
56 fixed_ips=None, key_pairs=None, instances=None,
ivan-zhub6d69ee2013-12-17 14:16:31 +080057 security_group_rules=None, cores=None,
ivan-zhu24358182013-11-27 15:08:06 +080058 security_groups=None):
59 """
60 Updates the tenant's quota limits for one or more resources
61 """
62 post_body = {}
63
64 if force is not None:
65 post_body['force'] = force
66
ivan-zhu24358182013-11-27 15:08:06 +080067 if metadata_items is not None:
68 post_body['metadata_items'] = metadata_items
69
70 if ram is not None:
71 post_body['ram'] = ram
72
73 if floating_ips is not None:
74 post_body['floating_ips'] = floating_ips
75
76 if fixed_ips is not None:
77 post_body['fixed_ips'] = fixed_ips
78
79 if key_pairs is not None:
80 post_body['key_pairs'] = key_pairs
81
82 if instances is not None:
83 post_body['instances'] = instances
84
85 if security_group_rules is not None:
86 post_body['security_group_rules'] = security_group_rules
87
ivan-zhu24358182013-11-27 15:08:06 +080088 if cores is not None:
89 post_body['cores'] = cores
90
ivan-zhu24358182013-11-27 15:08:06 +080091 if security_groups is not None:
92 post_body['security_groups'] = security_groups
93
94 post_body = json.dumps({'quota_set': post_body})
vponomaryovf4c27f92014-02-18 10:56:42 +020095 resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body)
ivan-zhu24358182013-11-27 15:08:06 +080096
97 body = json.loads(body)
98 return resp, body['quota_set']