blob: 785d546357d317200ef22fcf49c9b0df3bf01cfd [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
19
Matthew Treinish33634462012-08-16 16:51:23 -040020NS = "{http://docs.openstack.org/common/api/v1.0}"
21
22
23class LimitsClientXML(RestClientXML):
24
25 def __init__(self, config, username, password, auth_url, tenant_name=None):
26 super(LimitsClientXML, self).__init__(config, username, password,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080027 auth_url, tenant_name)
Matthew Treinish33634462012-08-16 16:51:23 -040028 self.service = self.config.compute.catalog_type
29
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053030 def get_absolute_limits(self):
Matthew Treinish33634462012-08-16 16:51:23 -040031 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-ganesana4ab0072012-08-07 19:48:56 +053038 ret[attributes['name']] = attributes['value']
Matthew Treinish33634462012-08-16 16:51:23 -040039 return resp, ret
40
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053041 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 Treinish33634462012-08-16 16:51:23 -040046
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053047 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]