Kurt Taylor | 6a6f5be | 2013-04-02 18:53:47 -0400 | [diff] [blame] | 1 | # Copyright 2012 IBM Corp. |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 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 | |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 16 | from lxml import objectify |
| 17 | |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 18 | from tempest.common.rest_client import RestClientXML |
| 19 | |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 20 | NS = "{http://docs.openstack.org/common/api/v1.0}" |
| 21 | |
| 22 | |
| 23 | class LimitsClientXML(RestClientXML): |
| 24 | |
| 25 | def __init__(self, config, username, password, auth_url, tenant_name=None): |
| 26 | super(LimitsClientXML, self).__init__(config, username, password, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 27 | auth_url, tenant_name) |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 28 | self.service = self.config.compute.catalog_type |
| 29 | |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 30 | def get_absolute_limits(self): |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 31 | resp, body = self.get("limits", self.headers) |
| 32 | body = objectify.fromstring(body) |
| 33 | lim = NS + 'absolute' |
| 34 | ret = {} |
| 35 | |
| 36 | for el in body[lim].iterchildren(): |
| 37 | attributes = el.attrib |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 38 | ret[attributes['name']] = attributes['value'] |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 39 | return resp, ret |
| 40 | |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 41 | def get_specific_absolute_limit(self, absolute_limit): |
| 42 | resp, body = self.get("limits", self.headers) |
| 43 | body = objectify.fromstring(body) |
| 44 | lim = NS + 'absolute' |
| 45 | ret = {} |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 46 | |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 47 | for el in body[lim].iterchildren(): |
| 48 | attributes = el.attrib |
| 49 | ret[attributes['name']] = attributes['value'] |
| 50 | if absolute_limit not in ret: |
| 51 | return None |
| 52 | else: |
| 53 | return ret[absolute_limit] |