rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [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 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 16 | from lxml import etree |
| 17 | |
vponomaryov | 960eeb4 | 2014-02-22 18:25:25 +0200 | [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 |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 20 | from tempest.services.compute.xml.common import Document |
| 21 | from tempest.services.compute.xml.common import Element |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 22 | from tempest.services.compute.xml.common import xml_to_json |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 23 | from tempest.services.compute.xml.common import XMLNS_11 |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 24 | |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 25 | CONF = config.CONF |
| 26 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 27 | |
vponomaryov | 960eeb4 | 2014-02-22 18:25:25 +0200 | [diff] [blame] | 28 | class QuotasClientXML(rest_client.RestClient): |
| 29 | TYPE = "xml" |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 30 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 31 | def __init__(self, auth_provider): |
| 32 | super(QuotasClientXML, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 33 | self.service = CONF.compute.catalog_type |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 34 | |
| 35 | def _format_quota(self, q): |
| 36 | quota = {} |
| 37 | for k, v in q.items(): |
| 38 | try: |
| 39 | v = int(v) |
| 40 | except ValueError: |
| 41 | pass |
| 42 | |
| 43 | quota[k] = v |
| 44 | |
| 45 | return quota |
| 46 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 47 | def get_quota_set(self, tenant_id): |
| 48 | """List the quota set for a tenant.""" |
| 49 | |
| 50 | url = 'os-quota-sets/%s' % str(tenant_id) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 51 | resp, body = self.get(url) |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 52 | body = xml_to_json(etree.fromstring(body)) |
| 53 | body = self._format_quota(body) |
| 54 | return resp, body |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 55 | |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 56 | def get_default_quota_set(self, tenant_id): |
| 57 | """List the default quota set for a tenant.""" |
| 58 | |
| 59 | url = 'os-quota-sets/%s/defaults' % str(tenant_id) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 60 | resp, body = self.get(url) |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 61 | body = xml_to_json(etree.fromstring(body)) |
| 62 | body = self._format_quota(body) |
| 63 | return resp, body |
| 64 | |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 65 | def update_quota_set(self, tenant_id, force=None, |
| 66 | injected_file_content_bytes=None, |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 67 | metadata_items=None, ram=None, floating_ips=None, |
Leo Toyoda | d540779 | 2013-03-28 14:57:15 +0900 | [diff] [blame] | 68 | fixed_ips=None, key_pairs=None, instances=None, |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 69 | security_group_rules=None, injected_files=None, |
| 70 | cores=None, injected_file_path_bytes=None, |
| 71 | security_groups=None): |
| 72 | """ |
| 73 | Updates the tenant's quota limits for one or more resources |
| 74 | """ |
| 75 | post_body = Element("quota_set", |
| 76 | xmlns=XMLNS_11) |
| 77 | |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 78 | if force is not None: |
| 79 | post_body.add_attr('force', force) |
| 80 | |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 81 | if injected_file_content_bytes is not None: |
| 82 | post_body.add_attr('injected_file_content_bytes', |
| 83 | injected_file_content_bytes) |
| 84 | |
| 85 | if metadata_items is not None: |
| 86 | post_body.add_attr('metadata_items', metadata_items) |
| 87 | |
| 88 | if ram is not None: |
| 89 | post_body.add_attr('ram', ram) |
| 90 | |
| 91 | if floating_ips is not None: |
| 92 | post_body.add_attr('floating_ips', floating_ips) |
| 93 | |
Leo Toyoda | d540779 | 2013-03-28 14:57:15 +0900 | [diff] [blame] | 94 | if fixed_ips is not None: |
| 95 | post_body.add_attr('fixed_ips', fixed_ips) |
| 96 | |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 97 | if key_pairs is not None: |
| 98 | post_body.add_attr('key_pairs', key_pairs) |
| 99 | |
| 100 | if instances is not None: |
| 101 | post_body.add_attr('instances', instances) |
| 102 | |
| 103 | if security_group_rules is not None: |
| 104 | post_body.add_attr('security_group_rules', security_group_rules) |
| 105 | |
| 106 | if injected_files is not None: |
| 107 | post_body.add_attr('injected_files', injected_files) |
| 108 | |
| 109 | if cores is not None: |
| 110 | post_body.add_attr('cores', cores) |
| 111 | |
| 112 | if injected_file_path_bytes is not None: |
| 113 | post_body.add_attr('injected_file_path_bytes', |
| 114 | injected_file_path_bytes) |
| 115 | |
| 116 | if security_groups is not None: |
| 117 | post_body.add_attr('security_groups', security_groups) |
| 118 | |
| 119 | resp, body = self.put('os-quota-sets/%s' % str(tenant_id), |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 120 | str(Document(post_body))) |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 121 | body = xml_to_json(etree.fromstring(body)) |
| 122 | body = self._format_quota(body) |
| 123 | return resp, body |
Yuiko Takada | 2209cf5 | 2014-02-27 12:03:49 +0000 | [diff] [blame] | 124 | |
| 125 | def delete_quota_set(self, tenant_id): |
| 126 | """Delete the tenant's quota set.""" |
| 127 | return self.delete('os-quota-sets/%s' % str(tenant_id)) |