blob: 5b1e48f73941809048cb4cb10daf3a5754967a6f [file] [log] [blame]
Rohit Karajgi07599c52012-11-02 05:35:16 -07001# 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
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053023class QuotasClientJSON(RestClient):
Rohit Karajgi07599c52012-11-02 05:35:16 -070024
25 def __init__(self, config, username, password, auth_url, tenant_name=None):
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053026 super(QuotasClientJSON, self).__init__(config, username, password,
27 auth_url, tenant_name)
Rohit Karajgi07599c52012-11-02 05:35:16 -070028 self.service = self.config.compute.catalog_type
29
30 def get_quota_set(self, tenant_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050031 """List the quota set for a tenant."""
Rohit Karajgi07599c52012-11-02 05:35:16 -070032
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']
Attila Fazekas4ba36582013-02-12 08:26:17 +010037
Leo Toyoda87a52b72013-04-09 10:34:40 +090038 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
Attila Fazekas4ba36582013-02-12 08:26:17 +010046 def update_quota_set(self, tenant_id, injected_file_content_bytes=None,
47 metadata_items=None, ram=None, floating_ips=None,
Leo Toyodad5407792013-03-28 14:57:15 +090048 fixed_ips=None, key_pairs=None, instances=None,
Attila Fazekas4ba36582013-02-12 08:26:17 +010049 security_group_rules=None, injected_files=None,
50 cores=None, injected_file_path_bytes=None,
51 security_groups=None):
52 """
53 Updates the tenant's quota limits for one or more resources
54 """
55 post_body = {}
56
57 if injected_file_content_bytes is not None:
58 post_body['injected_file_content_bytes'] = \
59 injected_file_content_bytes
60
61 if metadata_items is not None:
62 post_body['metadata_items'] = metadata_items
63
64 if ram is not None:
65 post_body['ram'] = ram
66
67 if floating_ips is not None:
68 post_body['floating_ips'] = floating_ips
69
Leo Toyodad5407792013-03-28 14:57:15 +090070 if fixed_ips is not None:
71 post_body['fixed_ips'] = fixed_ips
72
Attila Fazekas4ba36582013-02-12 08:26:17 +010073 if key_pairs is not None:
74 post_body['key_pairs'] = key_pairs
75
76 if instances is not None:
77 post_body['instances'] = instances
78
79 if security_group_rules is not None:
80 post_body['security_group_rules'] = security_group_rules
81
82 if injected_files is not None:
83 post_body['injected_files'] = injected_files
84
85 if cores is not None:
86 post_body['cores'] = cores
87
88 if injected_file_path_bytes is not None:
89 post_body['injected_file_path_bytes'] = injected_file_path_bytes
90
91 if security_groups is not None:
92 post_body['security_groups'] = security_groups
93
94 post_body = json.dumps({'quota_set': post_body})
95 resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body,
96 self.headers)
97
98 body = json.loads(body)
99 return resp, body['quota_set']