blob: ea0d3a2cc61bedd41cfba09de8c121096c1fe1e6 [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
Matthew Treinish684d8992014-01-30 16:27:40 +000026 def __init__(self, username, password, auth_url, tenant_name=None):
27 super(QuotasV3ClientJSON, self).__init__(username, password,
ivan-zhub6d69ee2013-12-17 14:16:31 +080028 auth_url, tenant_name)
Matthew Treinish684d8992014-01-30 16:27:40 +000029 self.service = CONF.compute.catalog_v3_type
ivan-zhu24358182013-11-27 15:08:06 +080030
31 def get_quota_set(self, tenant_id):
32 """List the quota set for a tenant."""
33
34 url = 'os-quota-sets/%s' % str(tenant_id)
35 resp, body = self.get(url)
36 body = json.loads(body)
37 return resp, body['quota_set']
38
39 def get_default_quota_set(self, tenant_id):
40 """List the default quota set for a tenant."""
41
42 url = 'os-quota-sets/%s/defaults' % str(tenant_id)
43 resp, body = self.get(url)
44 body = json.loads(body)
45 return resp, body['quota_set']
46
47 def update_quota_set(self, tenant_id, force=None,
ivan-zhu24358182013-11-27 15:08:06 +080048 metadata_items=None, ram=None, floating_ips=None,
49 fixed_ips=None, key_pairs=None, instances=None,
ivan-zhub6d69ee2013-12-17 14:16:31 +080050 security_group_rules=None, cores=None,
ivan-zhu24358182013-11-27 15:08:06 +080051 security_groups=None):
52 """
53 Updates the tenant's quota limits for one or more resources
54 """
55 post_body = {}
56
57 if force is not None:
58 post_body['force'] = force
59
ivan-zhu24358182013-11-27 15:08:06 +080060 if metadata_items is not None:
61 post_body['metadata_items'] = metadata_items
62
63 if ram is not None:
64 post_body['ram'] = ram
65
66 if floating_ips is not None:
67 post_body['floating_ips'] = floating_ips
68
69 if fixed_ips is not None:
70 post_body['fixed_ips'] = fixed_ips
71
72 if key_pairs is not None:
73 post_body['key_pairs'] = key_pairs
74
75 if instances is not None:
76 post_body['instances'] = instances
77
78 if security_group_rules is not None:
79 post_body['security_group_rules'] = security_group_rules
80
ivan-zhu24358182013-11-27 15:08:06 +080081 if cores is not None:
82 post_body['cores'] = cores
83
ivan-zhu24358182013-11-27 15:08:06 +080084 if security_groups is not None:
85 post_body['security_groups'] = security_groups
86
87 post_body = json.dumps({'quota_set': post_body})
88 resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body,
89 self.headers)
90
91 body = json.loads(body)
92 return resp, body['quota_set']