blob: cae233225c363c355ccab0257ef4253f43bf2348 [file] [log] [blame]
ivan-zhu24358182013-11-27 15:08:06 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2#
3# Copyright 2012 NTT Data
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import json
19
20from tempest.common.rest_client import RestClient
21
22
ivan-zhub6d69ee2013-12-17 14:16:31 +080023class QuotasV3ClientJSON(RestClient):
ivan-zhu24358182013-11-27 15:08:06 +080024
25 def __init__(self, config, username, password, auth_url, tenant_name=None):
ivan-zhub6d69ee2013-12-17 14:16:31 +080026 super(QuotasV3ClientJSON, self).__init__(config, username, password,
27 auth_url, tenant_name)
28 self.service = self.config.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
38 def get_default_quota_set(self, tenant_id):
39 """List the default quota set for a tenant."""
40
41 url = 'os-quota-sets/%s/defaults' % str(tenant_id)
42 resp, body = self.get(url)
43 body = json.loads(body)
44 return resp, body['quota_set']
45
46 def update_quota_set(self, tenant_id, force=None,
ivan-zhu24358182013-11-27 15:08:06 +080047 metadata_items=None, ram=None, floating_ips=None,
48 fixed_ips=None, key_pairs=None, instances=None,
ivan-zhub6d69ee2013-12-17 14:16:31 +080049 security_group_rules=None, cores=None,
ivan-zhu24358182013-11-27 15:08:06 +080050 security_groups=None):
51 """
52 Updates the tenant's quota limits for one or more resources
53 """
54 post_body = {}
55
56 if force is not None:
57 post_body['force'] = force
58
ivan-zhu24358182013-11-27 15:08:06 +080059 if metadata_items is not None:
60 post_body['metadata_items'] = metadata_items
61
62 if ram is not None:
63 post_body['ram'] = ram
64
65 if floating_ips is not None:
66 post_body['floating_ips'] = floating_ips
67
68 if fixed_ips is not None:
69 post_body['fixed_ips'] = fixed_ips
70
71 if key_pairs is not None:
72 post_body['key_pairs'] = key_pairs
73
74 if instances is not None:
75 post_body['instances'] = instances
76
77 if security_group_rules is not None:
78 post_body['security_group_rules'] = security_group_rules
79
ivan-zhu24358182013-11-27 15:08:06 +080080 if cores is not None:
81 post_body['cores'] = cores
82
ivan-zhu24358182013-11-27 15:08:06 +080083 if security_groups is not None:
84 post_body['security_groups'] = security_groups
85
86 post_body = json.dumps({'quota_set': post_body})
87 resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body,
88 self.headers)
89
90 body = json.loads(body)
91 return resp, body['quota_set']