blob: f9f02a5f88189badd4e6fe33fd045de28e3627e6 [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
Marc Koderer6fbd74f2014-08-04 09:38:19 +020018from tempest.api_schema.response.compute.v2\
19 import quota_classes as classes_schema
20from tempest.api_schema.response.compute.v2 import quotas as schema
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +000021from tempest.common import service_client
Rohit Karajgi07599c52012-11-02 05:35:16 -070022
23
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +000024class QuotasClientJSON(service_client.ServiceClient):
Rohit Karajgi07599c52012-11-02 05:35:16 -070025
Zhi Kun Liu90e41312014-03-06 14:56:01 +080026 def get_quota_set(self, tenant_id, user_id=None):
Sean Daguef237ccb2013-01-04 15:19:14 -050027 """List the quota set for a tenant."""
Rohit Karajgi07599c52012-11-02 05:35:16 -070028
29 url = 'os-quota-sets/%s' % str(tenant_id)
Zhi Kun Liu90e41312014-03-06 14:56:01 +080030 if user_id:
31 url += '?user_id=%s' % str(user_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070032 resp, body = self.get(url)
33 body = json.loads(body)
Yuiko Takada26c3b172014-03-19 14:03:28 +000034 self.validate_response(schema.quota_set, resp, body)
Rohit Karajgi07599c52012-11-02 05:35:16 -070035 return resp, body['quota_set']
Attila Fazekas4ba36582013-02-12 08:26:17 +010036
Leo Toyoda87a52b72013-04-09 10:34:40 +090037 def get_default_quota_set(self, tenant_id):
38 """List the default quota set for a tenant."""
39
40 url = 'os-quota-sets/%s/defaults' % str(tenant_id)
41 resp, body = self.get(url)
42 body = json.loads(body)
Yuiko Takada26c3b172014-03-19 14:03:28 +000043 self.validate_response(schema.quota_set, resp, body)
Leo Toyoda87a52b72013-04-09 10:34:40 +090044 return resp, body['quota_set']
45
Zhi Kun Liu27e154f2014-03-24 03:51:12 -050046 def update_quota_set(self, tenant_id, user_id=None,
47 force=None, injected_file_content_bytes=None,
Attila Fazekas4ba36582013-02-12 08:26:17 +010048 metadata_items=None, ram=None, floating_ips=None,
Leo Toyodad5407792013-03-28 14:57:15 +090049 fixed_ips=None, key_pairs=None, instances=None,
Attila Fazekas4ba36582013-02-12 08:26:17 +010050 security_group_rules=None, injected_files=None,
51 cores=None, injected_file_path_bytes=None,
52 security_groups=None):
53 """
54 Updates the tenant's quota limits for one or more resources
55 """
56 post_body = {}
57
gengjh07fe8302013-04-17 16:15:22 +080058 if force is not None:
59 post_body['force'] = force
60
Attila Fazekas4ba36582013-02-12 08:26:17 +010061 if injected_file_content_bytes is not None:
62 post_body['injected_file_content_bytes'] = \
63 injected_file_content_bytes
64
65 if metadata_items is not None:
66 post_body['metadata_items'] = metadata_items
67
68 if ram is not None:
69 post_body['ram'] = ram
70
71 if floating_ips is not None:
72 post_body['floating_ips'] = floating_ips
73
Leo Toyodad5407792013-03-28 14:57:15 +090074 if fixed_ips is not None:
75 post_body['fixed_ips'] = fixed_ips
76
Attila Fazekas4ba36582013-02-12 08:26:17 +010077 if key_pairs is not None:
78 post_body['key_pairs'] = key_pairs
79
80 if instances is not None:
81 post_body['instances'] = instances
82
83 if security_group_rules is not None:
84 post_body['security_group_rules'] = security_group_rules
85
86 if injected_files is not None:
87 post_body['injected_files'] = injected_files
88
89 if cores is not None:
90 post_body['cores'] = cores
91
92 if injected_file_path_bytes is not None:
93 post_body['injected_file_path_bytes'] = injected_file_path_bytes
94
95 if security_groups is not None:
96 post_body['security_groups'] = security_groups
97
98 post_body = json.dumps({'quota_set': post_body})
Zhi Kun Liu27e154f2014-03-24 03:51:12 -050099
100 if user_id:
101 resp, body = self.put('os-quota-sets/%s?user_id=%s' %
102 (str(tenant_id), str(user_id)), post_body)
103 else:
104 resp, body = self.put('os-quota-sets/%s' % str(tenant_id),
105 post_body)
Attila Fazekas4ba36582013-02-12 08:26:17 +0100106
107 body = json.loads(body)
Yuiko Takada3657ae82014-03-25 09:52:15 +0000108 self.validate_response(schema.quota_set_update, resp, body)
Attila Fazekas4ba36582013-02-12 08:26:17 +0100109 return resp, body['quota_set']
Yuiko Takada2209cf52014-02-27 12:03:49 +0000110
111 def delete_quota_set(self, tenant_id):
112 """Delete the tenant's quota set."""
Yuiko Takadaa3d584d2014-04-03 14:11:53 +0000113 resp, body = self.delete('os-quota-sets/%s' % str(tenant_id))
114 self.validate_response(schema.delete_quota, resp, body)
115 return resp, body
Matt Riedemann848805f2014-06-16 13:23:51 -0700116
117
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +0000118class QuotaClassesClientJSON(service_client.ServiceClient):
Matt Riedemann848805f2014-06-16 13:23:51 -0700119
120 def get_quota_class_set(self, quota_class_id):
121 """List the quota class set for a quota class."""
122
123 url = 'os-quota-class-sets/%s' % str(quota_class_id)
124 resp, body = self.get(url)
125 body = json.loads(body)
126 self.validate_response(classes_schema.quota_set, resp, body)
127 return resp, body['quota_class_set']
128
129 def update_quota_class_set(self, quota_class_id, **kwargs):
130 """
131 Updates the quota class's limits for one or more resources.
132 """
133 post_body = json.dumps({'quota_class_set': kwargs})
134
135 resp, body = self.put('os-quota-class-sets/%s' % str(quota_class_id),
136 post_body)
137
138 body = json.loads(body)
139 self.validate_response(classes_schema.quota_set_update, resp, body)
140 return resp, body['quota_class_set']