blob: 93461839a0755a8dd726a1ef105c937c2231f9ea [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
Yuiko Takada26c3b172014-03-19 14:03:28 +000018from tempest.api_schema.compute.v2 import quotas as schema
Haiwei Xuab924622014-03-05 04:33:51 +090019from tempest.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000020from tempest import config
21
22CONF = config.CONF
Rohit Karajgi07599c52012-11-02 05:35:16 -070023
24
Haiwei Xuab924622014-03-05 04:33:51 +090025class QuotasClientJSON(rest_client.RestClient):
Rohit Karajgi07599c52012-11-02 05:35:16 -070026
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000027 def __init__(self, auth_provider):
28 super(QuotasClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000029 self.service = CONF.compute.catalog_type
Rohit Karajgi07599c52012-11-02 05:35:16 -070030
Zhi Kun Liu90e41312014-03-06 14:56:01 +080031 def get_quota_set(self, tenant_id, user_id=None):
Sean Daguef237ccb2013-01-04 15:19:14 -050032 """List the quota set for a tenant."""
Rohit Karajgi07599c52012-11-02 05:35:16 -070033
34 url = 'os-quota-sets/%s' % str(tenant_id)
Zhi Kun Liu90e41312014-03-06 14:56:01 +080035 if user_id:
36 url += '?user_id=%s' % str(user_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070037 resp, body = self.get(url)
38 body = json.loads(body)
Yuiko Takada26c3b172014-03-19 14:03:28 +000039 self.validate_response(schema.quota_set, resp, body)
Rohit Karajgi07599c52012-11-02 05:35:16 -070040 return resp, body['quota_set']
Attila Fazekas4ba36582013-02-12 08:26:17 +010041
Leo Toyoda87a52b72013-04-09 10:34:40 +090042 def get_default_quota_set(self, tenant_id):
43 """List the default quota set for a tenant."""
44
45 url = 'os-quota-sets/%s/defaults' % str(tenant_id)
46 resp, body = self.get(url)
47 body = json.loads(body)
Yuiko Takada26c3b172014-03-19 14:03:28 +000048 self.validate_response(schema.quota_set, resp, body)
Leo Toyoda87a52b72013-04-09 10:34:40 +090049 return resp, body['quota_set']
50
gengjh07fe8302013-04-17 16:15:22 +080051 def update_quota_set(self, tenant_id, force=None,
52 injected_file_content_bytes=None,
Attila Fazekas4ba36582013-02-12 08:26:17 +010053 metadata_items=None, ram=None, floating_ips=None,
Leo Toyodad5407792013-03-28 14:57:15 +090054 fixed_ips=None, key_pairs=None, instances=None,
Attila Fazekas4ba36582013-02-12 08:26:17 +010055 security_group_rules=None, injected_files=None,
56 cores=None, injected_file_path_bytes=None,
57 security_groups=None):
58 """
59 Updates the tenant's quota limits for one or more resources
60 """
61 post_body = {}
62
gengjh07fe8302013-04-17 16:15:22 +080063 if force is not None:
64 post_body['force'] = force
65
Attila Fazekas4ba36582013-02-12 08:26:17 +010066 if injected_file_content_bytes is not None:
67 post_body['injected_file_content_bytes'] = \
68 injected_file_content_bytes
69
70 if metadata_items is not None:
71 post_body['metadata_items'] = metadata_items
72
73 if ram is not None:
74 post_body['ram'] = ram
75
76 if floating_ips is not None:
77 post_body['floating_ips'] = floating_ips
78
Leo Toyodad5407792013-03-28 14:57:15 +090079 if fixed_ips is not None:
80 post_body['fixed_ips'] = fixed_ips
81
Attila Fazekas4ba36582013-02-12 08:26:17 +010082 if key_pairs is not None:
83 post_body['key_pairs'] = key_pairs
84
85 if instances is not None:
86 post_body['instances'] = instances
87
88 if security_group_rules is not None:
89 post_body['security_group_rules'] = security_group_rules
90
91 if injected_files is not None:
92 post_body['injected_files'] = injected_files
93
94 if cores is not None:
95 post_body['cores'] = cores
96
97 if injected_file_path_bytes is not None:
98 post_body['injected_file_path_bytes'] = injected_file_path_bytes
99
100 if security_groups is not None:
101 post_body['security_groups'] = security_groups
102
103 post_body = json.dumps({'quota_set': post_body})
vponomaryovf4c27f92014-02-18 10:56:42 +0200104 resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body)
Attila Fazekas4ba36582013-02-12 08:26:17 +0100105
106 body = json.loads(body)
107 return resp, body['quota_set']
Yuiko Takada2209cf52014-02-27 12:03:49 +0000108
109 def delete_quota_set(self, tenant_id):
110 """Delete the tenant's quota set."""
111 return self.delete('os-quota-sets/%s' % str(tenant_id))