Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 1 | # 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 | |
| 16 | import json |
| 17 | |
Marc Koderer | 6fbd74f | 2014-08-04 09:38:19 +0200 | [diff] [blame] | 18 | from tempest.api_schema.response.compute.v2\ |
| 19 | import quota_classes as classes_schema |
| 20 | from tempest.api_schema.response.compute.v2 import quotas as schema |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 21 | from tempest.common import service_client |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 22 | |
| 23 | |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 24 | class QuotasClientJSON(service_client.ServiceClient): |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 25 | |
Zhi Kun Liu | 90e4131 | 2014-03-06 14:56:01 +0800 | [diff] [blame] | 26 | def get_quota_set(self, tenant_id, user_id=None): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 27 | """List the quota set for a tenant.""" |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 28 | |
| 29 | url = 'os-quota-sets/%s' % str(tenant_id) |
Zhi Kun Liu | 90e4131 | 2014-03-06 14:56:01 +0800 | [diff] [blame] | 30 | if user_id: |
| 31 | url += '?user_id=%s' % str(user_id) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 32 | resp, body = self.get(url) |
| 33 | body = json.loads(body) |
Yuiko Takada | 26c3b17 | 2014-03-19 14:03:28 +0000 | [diff] [blame] | 34 | self.validate_response(schema.quota_set, resp, body) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 35 | return resp, body['quota_set'] |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 36 | |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 37 | 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 Takada | 26c3b17 | 2014-03-19 14:03:28 +0000 | [diff] [blame] | 43 | self.validate_response(schema.quota_set, resp, body) |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 44 | return resp, body['quota_set'] |
| 45 | |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 46 | def update_quota_set(self, tenant_id, user_id=None, |
| 47 | force=None, injected_file_content_bytes=None, |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 48 | metadata_items=None, ram=None, floating_ips=None, |
Leo Toyoda | d540779 | 2013-03-28 14:57:15 +0900 | [diff] [blame] | 49 | fixed_ips=None, key_pairs=None, instances=None, |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 50 | 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 | |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 58 | if force is not None: |
| 59 | post_body['force'] = force |
| 60 | |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 61 | 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 Toyoda | d540779 | 2013-03-28 14:57:15 +0900 | [diff] [blame] | 74 | if fixed_ips is not None: |
| 75 | post_body['fixed_ips'] = fixed_ips |
| 76 | |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 77 | 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 Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 99 | |
| 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 Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 106 | |
| 107 | body = json.loads(body) |
Yuiko Takada | 3657ae8 | 2014-03-25 09:52:15 +0000 | [diff] [blame] | 108 | self.validate_response(schema.quota_set_update, resp, body) |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 109 | return resp, body['quota_set'] |
Yuiko Takada | 2209cf5 | 2014-02-27 12:03:49 +0000 | [diff] [blame] | 110 | |
| 111 | def delete_quota_set(self, tenant_id): |
| 112 | """Delete the tenant's quota set.""" |
Yuiko Takada | a3d584d | 2014-04-03 14:11:53 +0000 | [diff] [blame] | 113 | 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 Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 116 | |
| 117 | |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 118 | class QuotaClassesClientJSON(service_client.ServiceClient): |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 119 | |
| 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'] |