blob: 232762672b11867892ee0a8669005506c0e0b66f [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
vponomaryov960eeb42014-02-22 18:25:25 +020018from tempest.common import rest_client
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
vponomaryov960eeb42014-02-22 18:25:25 +020026class LimitsClientXML(rest_client.RestClient):
27 TYPE = "xml"
Matthew Treinish33634462012-08-16 16:51:23 -040028
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000029 def __init__(self, auth_provider):
30 super(LimitsClientXML, self).__init__(auth_provider)
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):
vponomaryovf4c27f92014-02-18 10:56:42 +020034 resp, body = self.get("limits")
Matthew Treinish33634462012-08-16 16:51:23 -040035 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):
vponomaryovf4c27f92014-02-18 10:56:42 +020045 resp, body = self.get("limits")
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053046 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]