ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [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 | |
| 18 | from tempest.common.rest_client import RestClient |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 19 | from tempest import config |
| 20 | |
| 21 | CONF = config.CONF |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 22 | |
| 23 | |
ivan-zhu | b6d69ee | 2013-12-17 14:16:31 +0800 | [diff] [blame] | 24 | class QuotasV3ClientJSON(RestClient): |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 25 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 26 | def __init__(self, auth_provider): |
| 27 | super(QuotasV3ClientJSON, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 28 | self.service = CONF.compute.catalog_v3_type |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 29 | |
| 30 | def get_quota_set(self, tenant_id): |
| 31 | """List the quota set for a tenant.""" |
| 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'] |
| 37 | |
Ken'ichi Ohmichi | 776cda6 | 2014-02-18 21:21:23 +0900 | [diff] [blame] | 38 | def get_quota_set_detail(self, tenant_id): |
| 39 | """Get the quota set detail for a tenant.""" |
| 40 | |
| 41 | url = 'os-quota-sets/%s/detail' % str(tenant_id) |
| 42 | resp, body = self.get(url) |
| 43 | body = json.loads(body) |
| 44 | return resp, body['quota_set'] |
| 45 | |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 46 | def get_default_quota_set(self, tenant_id): |
| 47 | """List the default quota set for a tenant.""" |
| 48 | |
| 49 | url = 'os-quota-sets/%s/defaults' % str(tenant_id) |
| 50 | resp, body = self.get(url) |
| 51 | body = json.loads(body) |
| 52 | return resp, body['quota_set'] |
| 53 | |
| 54 | def update_quota_set(self, tenant_id, force=None, |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 55 | metadata_items=None, ram=None, floating_ips=None, |
| 56 | fixed_ips=None, key_pairs=None, instances=None, |
ivan-zhu | b6d69ee | 2013-12-17 14:16:31 +0800 | [diff] [blame] | 57 | security_group_rules=None, cores=None, |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 58 | security_groups=None): |
| 59 | """ |
| 60 | Updates the tenant's quota limits for one or more resources |
| 61 | """ |
| 62 | post_body = {} |
| 63 | |
| 64 | if force is not None: |
| 65 | post_body['force'] = force |
| 66 | |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 67 | if metadata_items is not None: |
| 68 | post_body['metadata_items'] = metadata_items |
| 69 | |
| 70 | if ram is not None: |
| 71 | post_body['ram'] = ram |
| 72 | |
| 73 | if floating_ips is not None: |
| 74 | post_body['floating_ips'] = floating_ips |
| 75 | |
| 76 | if fixed_ips is not None: |
| 77 | post_body['fixed_ips'] = fixed_ips |
| 78 | |
| 79 | if key_pairs is not None: |
| 80 | post_body['key_pairs'] = key_pairs |
| 81 | |
| 82 | if instances is not None: |
| 83 | post_body['instances'] = instances |
| 84 | |
| 85 | if security_group_rules is not None: |
| 86 | post_body['security_group_rules'] = security_group_rules |
| 87 | |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 88 | if cores is not None: |
| 89 | post_body['cores'] = cores |
| 90 | |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 91 | if security_groups is not None: |
| 92 | post_body['security_groups'] = security_groups |
| 93 | |
| 94 | post_body = json.dumps({'quota_set': post_body}) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 95 | resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body) |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 96 | |
| 97 | body = json.loads(body) |
| 98 | return resp, body['quota_set'] |