blob: 229dbee7c3c8394fc5a7bd446e16d861a103a51f [file] [log] [blame]
Matthew Treinish33634462012-08-16 16:51:23 -04001# 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
18from tempest.common.rest_client import RestClientXML
19from lxml import etree
20from lxml import objectify
21
22NS = "{http://docs.openstack.org/common/api/v1.0}"
23
24
25class LimitsClientXML(RestClientXML):
26
27 def __init__(self, config, username, password, auth_url, tenant_name=None):
28 super(LimitsClientXML, self).__init__(config, username, password,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080029 auth_url, tenant_name)
Matthew Treinish33634462012-08-16 16:51:23 -040030 self.service = self.config.compute.catalog_type
31
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053032 def get_absolute_limits(self):
Matthew Treinish33634462012-08-16 16:51:23 -040033 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-ganesana4ab0072012-08-07 19:48:56 +053040 ret[attributes['name']] = attributes['value']
Matthew Treinish33634462012-08-16 16:51:23 -040041 return resp, ret
42
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053043 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 Treinish33634462012-08-16 16:51:23 -040048
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053049 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]