blob: b6ec9b829b9753230c4e90e059920c769669ca8e [file] [log] [blame]
Rohit Karajgi07599c52012-11-02 05:35:16 -07001# 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
19
20
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053021class QuotasClientJSON(RestClient):
Rohit Karajgi07599c52012-11-02 05:35:16 -070022
23 def __init__(self, config, username, password, auth_url, tenant_name=None):
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053024 super(QuotasClientJSON, self).__init__(config, username, password,
25 auth_url, tenant_name)
Rohit Karajgi07599c52012-11-02 05:35:16 -070026 self.service = self.config.compute.catalog_type
27
28 def get_quota_set(self, tenant_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050029 """List the quota set for a tenant."""
Rohit Karajgi07599c52012-11-02 05:35:16 -070030
31 url = 'os-quota-sets/%s' % str(tenant_id)
32 resp, body = self.get(url)
33 body = json.loads(body)
34 return resp, body['quota_set']
Attila Fazekas4ba36582013-02-12 08:26:17 +010035
Leo Toyoda87a52b72013-04-09 10:34:40 +090036 def get_default_quota_set(self, tenant_id):
37 """List the default quota set for a tenant."""
38
39 url = 'os-quota-sets/%s/defaults' % str(tenant_id)
40 resp, body = self.get(url)
41 body = json.loads(body)
42 return resp, body['quota_set']
43
gengjh07fe8302013-04-17 16:15:22 +080044 def update_quota_set(self, tenant_id, force=None,
45 injected_file_content_bytes=None,
Attila Fazekas4ba36582013-02-12 08:26:17 +010046 metadata_items=None, ram=None, floating_ips=None,
Leo Toyodad5407792013-03-28 14:57:15 +090047 fixed_ips=None, key_pairs=None, instances=None,
Attila Fazekas4ba36582013-02-12 08:26:17 +010048 security_group_rules=None, injected_files=None,
49 cores=None, injected_file_path_bytes=None,
50 security_groups=None):
51 """
52 Updates the tenant's quota limits for one or more resources
53 """
54 post_body = {}
55
gengjh07fe8302013-04-17 16:15:22 +080056 if force is not None:
57 post_body['force'] = force
58
Attila Fazekas4ba36582013-02-12 08:26:17 +010059 if injected_file_content_bytes is not None:
60 post_body['injected_file_content_bytes'] = \
61 injected_file_content_bytes
62
63 if metadata_items is not None:
64 post_body['metadata_items'] = metadata_items
65
66 if ram is not None:
67 post_body['ram'] = ram
68
69 if floating_ips is not None:
70 post_body['floating_ips'] = floating_ips
71
Leo Toyodad5407792013-03-28 14:57:15 +090072 if fixed_ips is not None:
73 post_body['fixed_ips'] = fixed_ips
74
Attila Fazekas4ba36582013-02-12 08:26:17 +010075 if key_pairs is not None:
76 post_body['key_pairs'] = key_pairs
77
78 if instances is not None:
79 post_body['instances'] = instances
80
81 if security_group_rules is not None:
82 post_body['security_group_rules'] = security_group_rules
83
84 if injected_files is not None:
85 post_body['injected_files'] = injected_files
86
87 if cores is not None:
88 post_body['cores'] = cores
89
90 if injected_file_path_bytes is not None:
91 post_body['injected_file_path_bytes'] = injected_file_path_bytes
92
93 if security_groups is not None:
94 post_body['security_groups'] = security_groups
95
96 post_body = json.dumps({'quota_set': post_body})
97 resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body,
98 self.headers)
99
100 body = json.loads(body)
101 return resp, body['quota_set']