blob: 5abaad808382a1f19d4497b974f8011f6749efb6 [file] [log] [blame]
Tony Yang3d5f1632013-06-06 14:17:57 +08001# Copyright 2013 IBM Corporation
2# 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
16from lxml import etree
17
18from tempest.common.rest_client import RestClientXML
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
Tony Yang3d5f1632013-06-06 14:17:57 +080020from tempest.services.compute.xml.common import xml_to_json
21
Matthew Treinish684d8992014-01-30 16:27:40 +000022CONF = config.CONF
23
Tony Yang3d5f1632013-06-06 14:17:57 +080024
25class HypervisorClientXML(RestClientXML):
26
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000027 def __init__(self, auth_provider):
28 super(HypervisorClientXML, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000029 self.service = CONF.compute.catalog_type
Tony Yang3d5f1632013-06-06 14:17:57 +080030
31 def _parse_array(self, node):
32 return [xml_to_json(x) for x in node]
33
34 def get_hypervisor_list(self):
35 """List hypervisors information."""
36 resp, body = self.get('os-hypervisors', self.headers)
37 hypervisors = self._parse_array(etree.fromstring(body))
38 return resp, hypervisors
39
40 def get_hypervisor_list_details(self):
41 """Show detailed hypervisors information."""
42 resp, body = self.get('os-hypervisors/detail', self.headers)
43 hypervisors = self._parse_array(etree.fromstring(body))
44 return resp, hypervisors
45
46 def get_hypervisor_show_details(self, hyper_id):
47 """Display the details of the specified hypervisor."""
48 resp, body = self.get('os-hypervisors/%s' % hyper_id,
49 self.headers)
50 hypervisor = xml_to_json(etree.fromstring(body))
51 return resp, hypervisor
52
53 def get_hypervisor_servers(self, hyper_name):
54 """List instances belonging to the specified hypervisor."""
55 resp, body = self.get('os-hypervisors/%s/servers' % hyper_name,
56 self.headers)
57 hypervisors = self._parse_array(etree.fromstring(body))
58 return resp, hypervisors
59
60 def get_hypervisor_stats(self):
61 """Get hypervisor statistics over all compute nodes."""
62 resp, body = self.get('os-hypervisors/statistics', self.headers)
63 stats = xml_to_json(etree.fromstring(body))
64 return resp, stats
65
66 def get_hypervisor_uptime(self, hyper_id):
67 """Display the uptime of the specified hypervisor."""
68 resp, body = self.get('os-hypervisors/%s/uptime' % hyper_id,
69 self.headers)
70 uptime = xml_to_json(etree.fromstring(body))
71 return resp, uptime
Lingxian Kong1629d5d2013-10-05 17:12:29 +080072
73 def search_hypervisor(self, hyper_name):
74 """Search specified hypervisor."""
75 resp, body = self.get('os-hypervisors/%s/search' % hyper_name,
76 self.headers)
77 hypervisors = self._parse_array(etree.fromstring(body))
78 return resp, hypervisors