Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | # |
| 3 | # Copyright 2012 IBM |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | from tempest.common.rest_client import RestClientXML |
| 19 | from lxml import etree |
| 20 | from lxml import objectify |
| 21 | |
| 22 | NS = "{http://docs.openstack.org/common/api/v1.0}" |
| 23 | |
| 24 | |
| 25 | class LimitsClientXML(RestClientXML): |
| 26 | |
| 27 | def __init__(self, config, username, password, auth_url, tenant_name=None): |
| 28 | super(LimitsClientXML, self).__init__(config, username, password, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 29 | auth_url, tenant_name) |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 30 | self.service = self.config.compute.catalog_type |
| 31 | |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 32 | def get_absolute_limits(self): |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 33 | resp, body = self.get("limits", self.headers) |
| 34 | body = objectify.fromstring(body) |
| 35 | lim = NS + 'absolute' |
| 36 | ret = {} |
| 37 | |
| 38 | for el in body[lim].iterchildren(): |
| 39 | attributes = el.attrib |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 40 | ret[attributes['name']] = attributes['value'] |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 41 | return resp, ret |
| 42 | |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 43 | def get_specific_absolute_limit(self, absolute_limit): |
| 44 | resp, body = self.get("limits", self.headers) |
| 45 | body = objectify.fromstring(body) |
| 46 | lim = NS + 'absolute' |
| 47 | ret = {} |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 48 | |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 49 | for el in body[lim].iterchildren(): |
| 50 | attributes = el.attrib |
| 51 | ret[attributes['name']] = attributes['value'] |
| 52 | if absolute_limit not in ret: |
| 53 | return None |
| 54 | else: |
| 55 | return ret[absolute_limit] |