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 | |
| 32 | def get_limits(self): |
| 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 |
| 40 | if attributes['name'] == 'maxServerMeta': |
| 41 | ret['maxServerMeta'] = int(attributes['value']) |
| 42 | elif attributes['name'] == 'maxPersonality': |
| 43 | ret['maxPersonality'] = int(attributes['value']) |
| 44 | elif attributes['name'] == 'maxPersonalitySize': |
| 45 | ret['maxPersonalitySize'] = int(attributes['value']) |
| 46 | |
| 47 | return resp, ret |
| 48 | |
| 49 | def get_max_server_meta(self): |
| 50 | resp, limits_dict = self.get_limits() |
| 51 | return resp, limits_dict['maxServerMeta'] |
| 52 | |
| 53 | def get_personality_file_limit(self): |
| 54 | resp, limits_dict = self.get_limits() |
| 55 | return resp, limits_dict['maxPersonality'] |
| 56 | |
| 57 | def get_personality_size_limit(self): |
| 58 | resp, limits_dict = self.get_limits() |
| 59 | return resp, limits_dict['maxPersonalitySize'] |