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 | |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame^] | 26 | def __init__(self, username, password, auth_url, tenant_name=None): |
| 27 | super(QuotasV3ClientJSON, self).__init__(username, password, |
ivan-zhu | b6d69ee | 2013-12-17 14:16:31 +0800 | [diff] [blame] | 28 | auth_url, tenant_name) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame^] | 29 | self.service = CONF.compute.catalog_v3_type |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 30 | |
| 31 | def get_quota_set(self, tenant_id): |
| 32 | """List the quota set for a tenant.""" |
| 33 | |
| 34 | url = 'os-quota-sets/%s' % str(tenant_id) |
| 35 | resp, body = self.get(url) |
| 36 | body = json.loads(body) |
| 37 | return resp, body['quota_set'] |
| 38 | |
| 39 | def get_default_quota_set(self, tenant_id): |
| 40 | """List the default quota set for a tenant.""" |
| 41 | |
| 42 | url = 'os-quota-sets/%s/defaults' % str(tenant_id) |
| 43 | resp, body = self.get(url) |
| 44 | body = json.loads(body) |
| 45 | return resp, body['quota_set'] |
| 46 | |
| 47 | def update_quota_set(self, tenant_id, force=None, |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 48 | metadata_items=None, ram=None, floating_ips=None, |
| 49 | fixed_ips=None, key_pairs=None, instances=None, |
ivan-zhu | b6d69ee | 2013-12-17 14:16:31 +0800 | [diff] [blame] | 50 | security_group_rules=None, cores=None, |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 51 | security_groups=None): |
| 52 | """ |
| 53 | Updates the tenant's quota limits for one or more resources |
| 54 | """ |
| 55 | post_body = {} |
| 56 | |
| 57 | if force is not None: |
| 58 | post_body['force'] = force |
| 59 | |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 60 | if metadata_items is not None: |
| 61 | post_body['metadata_items'] = metadata_items |
| 62 | |
| 63 | if ram is not None: |
| 64 | post_body['ram'] = ram |
| 65 | |
| 66 | if floating_ips is not None: |
| 67 | post_body['floating_ips'] = floating_ips |
| 68 | |
| 69 | if fixed_ips is not None: |
| 70 | post_body['fixed_ips'] = fixed_ips |
| 71 | |
| 72 | if key_pairs is not None: |
| 73 | post_body['key_pairs'] = key_pairs |
| 74 | |
| 75 | if instances is not None: |
| 76 | post_body['instances'] = instances |
| 77 | |
| 78 | if security_group_rules is not None: |
| 79 | post_body['security_group_rules'] = security_group_rules |
| 80 | |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 81 | if cores is not None: |
| 82 | post_body['cores'] = cores |
| 83 | |
ivan-zhu | 2435818 | 2013-11-27 15:08:06 +0800 | [diff] [blame] | 84 | if security_groups is not None: |
| 85 | post_body['security_groups'] = security_groups |
| 86 | |
| 87 | post_body = json.dumps({'quota_set': post_body}) |
| 88 | resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body, |
| 89 | self.headers) |
| 90 | |
| 91 | body = json.loads(body) |
| 92 | return resp, body['quota_set'] |