blob: 3c4f2b868855e0abd3eda3b89839fa07d505258c [file] [log] [blame]
Tony Yang3d5f1632013-06-06 14:17:57 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 IBM Corporation
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 lxml import etree
19
20from tempest.common.rest_client import RestClientXML
21from tempest.services.compute.xml.common import xml_to_json
22
23
24class HypervisorClientXML(RestClientXML):
25
26 def __init__(self, config, username, password, auth_url, tenant_name=None):
27 super(HypervisorClientXML, self).__init__(config, username,
28 password, auth_url,
29 tenant_name)
30 self.service = self.config.compute.catalog_type
31
32 def _parse_array(self, node):
33 return [xml_to_json(x) for x in node]
34
35 def get_hypervisor_list(self):
36 """List hypervisors information."""
37 resp, body = self.get('os-hypervisors', self.headers)
38 hypervisors = self._parse_array(etree.fromstring(body))
39 return resp, hypervisors
40
41 def get_hypervisor_list_details(self):
42 """Show detailed hypervisors information."""
43 resp, body = self.get('os-hypervisors/detail', self.headers)
44 hypervisors = self._parse_array(etree.fromstring(body))
45 return resp, hypervisors
46
47 def get_hypervisor_show_details(self, hyper_id):
48 """Display the details of the specified hypervisor."""
49 resp, body = self.get('os-hypervisors/%s' % hyper_id,
50 self.headers)
51 hypervisor = xml_to_json(etree.fromstring(body))
52 return resp, hypervisor
53
54 def get_hypervisor_servers(self, hyper_name):
55 """List instances belonging to the specified hypervisor."""
56 resp, body = self.get('os-hypervisors/%s/servers' % hyper_name,
57 self.headers)
58 hypervisors = self._parse_array(etree.fromstring(body))
59 return resp, hypervisors
60
61 def get_hypervisor_stats(self):
62 """Get hypervisor statistics over all compute nodes."""
63 resp, body = self.get('os-hypervisors/statistics', self.headers)
64 stats = xml_to_json(etree.fromstring(body))
65 return resp, stats
66
67 def get_hypervisor_uptime(self, hyper_id):
68 """Display the uptime of the specified hypervisor."""
69 resp, body = self.get('os-hypervisors/%s/uptime' % hyper_id,
70 self.headers)
71 uptime = xml_to_json(etree.fromstring(body))
72 return resp, uptime