blob: 923369774b339f7f94a21b12d68201b9b0b470cd [file] [log] [blame]
Kurt Taylor6a6f5be2013-04-02 18:53:47 -04001# Copyright 2012 IBM Corp.
Matthew Treinish33634462012-08-16 16:51:23 -04002# 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 Treinish33634462012-08-16 16:51:23 -040016from lxml import objectify
17
Matthew Treinisha83a16e2012-12-07 13:44:02 -050018from tempest.common.rest_client import RestClientXML
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
Matthew Treinisha83a16e2012-12-07 13:44:02 -050022
Matthew Treinish33634462012-08-16 16:51:23 -040023NS = "{http://docs.openstack.org/common/api/v1.0}"
24
25
26class LimitsClientXML(RestClientXML):
27
Matthew Treinish684d8992014-01-30 16:27:40 +000028 def __init__(self, username, password, auth_url, tenant_name=None):
29 super(LimitsClientXML, self).__init__(username, password,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080030 auth_url, tenant_name)
Matthew Treinish684d8992014-01-30 16:27:40 +000031 self.service = CONF.compute.catalog_type
Matthew Treinish33634462012-08-16 16:51:23 -040032
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053033 def get_absolute_limits(self):
Matthew Treinish33634462012-08-16 16:51:23 -040034 resp, body = self.get("limits", self.headers)
35 body = objectify.fromstring(body)
36 lim = NS + 'absolute'
37 ret = {}
38
39 for el in body[lim].iterchildren():
40 attributes = el.attrib
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053041 ret[attributes['name']] = attributes['value']
Matthew Treinish33634462012-08-16 16:51:23 -040042 return resp, ret
43
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053044 def get_specific_absolute_limit(self, absolute_limit):
45 resp, body = self.get("limits", self.headers)
46 body = objectify.fromstring(body)
47 lim = NS + 'absolute'
48 ret = {}
Matthew Treinish33634462012-08-16 16:51:23 -040049
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053050 for el in body[lim].iterchildren():
51 attributes = el.attrib
52 ret[attributes['name']] = attributes['value']
53 if absolute_limit not in ret:
54 return None
55 else:
56 return ret[absolute_limit]