blob: 37d4131a79aeecf206d1f38ad0c93fa225201319 [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
38 def update_quota_set(self, tenant_id, injected_file_content_bytes=None,
39 metadata_items=None, ram=None, floating_ips=None,
Leo Toyodad5407792013-03-28 14:57:15 +090040 fixed_ips=None, key_pairs=None, instances=None,
Attila Fazekas4ba36582013-02-12 08:26:17 +010041 security_group_rules=None, injected_files=None,
42 cores=None, injected_file_path_bytes=None,
43 security_groups=None):
44 """
45 Updates the tenant's quota limits for one or more resources
46 """
47 post_body = {}
48
49 if injected_file_content_bytes is not None:
50 post_body['injected_file_content_bytes'] = \
51 injected_file_content_bytes
52
53 if metadata_items is not None:
54 post_body['metadata_items'] = metadata_items
55
56 if ram is not None:
57 post_body['ram'] = ram
58
59 if floating_ips is not None:
60 post_body['floating_ips'] = floating_ips
61
Leo Toyodad5407792013-03-28 14:57:15 +090062 if fixed_ips is not None:
63 post_body['fixed_ips'] = fixed_ips
64
Attila Fazekas4ba36582013-02-12 08:26:17 +010065 if key_pairs is not None:
66 post_body['key_pairs'] = key_pairs
67
68 if instances is not None:
69 post_body['instances'] = instances
70
71 if security_group_rules is not None:
72 post_body['security_group_rules'] = security_group_rules
73
74 if injected_files is not None:
75 post_body['injected_files'] = injected_files
76
77 if cores is not None:
78 post_body['cores'] = cores
79
80 if injected_file_path_bytes is not None:
81 post_body['injected_file_path_bytes'] = injected_file_path_bytes
82
83 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']