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 | |
Haiwei Xu | ab92462 | 2014-03-05 04:33:51 +0900 | [diff] [blame] | 18 | from tempest.common import rest_client |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 19 | from tempest import config |
| 20 | |
| 21 | CONF = config.CONF |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 22 | |
| 23 | |
Haiwei Xu | ab92462 | 2014-03-05 04:33:51 +0900 | [diff] [blame] | 24 | class QuotasClientJSON(rest_client.RestClient): |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 25 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 26 | def __init__(self, auth_provider): |
| 27 | super(QuotasClientJSON, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 28 | self.service = CONF.compute.catalog_type |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 29 | |
| 30 | def get_quota_set(self, tenant_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 31 | """List the quota set for a tenant.""" |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 32 | |
| 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 Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 37 | |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 38 | 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 | |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 46 | def update_quota_set(self, tenant_id, force=None, |
| 47 | 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}) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 99 | resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body) |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 100 | |
| 101 | body = json.loads(body) |
| 102 | return resp, body['quota_set'] |