blob: ecd75416a74bf8956657850f24f1b3ab887e6954 [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
vponomaryov960eeb42014-02-22 18:25:25 +020018from tempest.common import rest_client
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
vponomaryov960eeb42014-02-22 18:25:25 +020025class HypervisorClientXML(rest_client.RestClient):
26 TYPE = "xml"
Tony Yang3d5f1632013-06-06 14:17:57 +080027
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000028 def __init__(self, auth_provider):
29 super(HypervisorClientXML, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000030 self.service = CONF.compute.catalog_type
Tony Yang3d5f1632013-06-06 14:17:57 +080031
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."""
vponomaryovf4c27f92014-02-18 10:56:42 +020037 resp, body = self.get('os-hypervisors')
Tony Yang3d5f1632013-06-06 14:17:57 +080038 hypervisors = self._parse_array(etree.fromstring(body))
39 return resp, hypervisors
40
41 def get_hypervisor_list_details(self):
42 """Show detailed hypervisors information."""
vponomaryovf4c27f92014-02-18 10:56:42 +020043 resp, body = self.get('os-hypervisors/detail')
Tony Yang3d5f1632013-06-06 14:17:57 +080044 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."""
vponomaryovf4c27f92014-02-18 10:56:42 +020049 resp, body = self.get('os-hypervisors/%s' % hyper_id)
Tony Yang3d5f1632013-06-06 14:17:57 +080050 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."""
vponomaryovf4c27f92014-02-18 10:56:42 +020055 resp, body = self.get('os-hypervisors/%s/servers' % hyper_name)
Tony Yang3d5f1632013-06-06 14:17:57 +080056 hypervisors = self._parse_array(etree.fromstring(body))
57 return resp, hypervisors
58
59 def get_hypervisor_stats(self):
60 """Get hypervisor statistics over all compute nodes."""
vponomaryovf4c27f92014-02-18 10:56:42 +020061 resp, body = self.get('os-hypervisors/statistics')
Tony Yang3d5f1632013-06-06 14:17:57 +080062 stats = xml_to_json(etree.fromstring(body))
63 return resp, stats
64
65 def get_hypervisor_uptime(self, hyper_id):
66 """Display the uptime of the specified hypervisor."""
vponomaryovf4c27f92014-02-18 10:56:42 +020067 resp, body = self.get('os-hypervisors/%s/uptime' % hyper_id)
Tony Yang3d5f1632013-06-06 14:17:57 +080068 uptime = xml_to_json(etree.fromstring(body))
69 return resp, uptime
Lingxian Kong1629d5d2013-10-05 17:12:29 +080070
71 def search_hypervisor(self, hyper_name):
72 """Search specified hypervisor."""
vponomaryovf4c27f92014-02-18 10:56:42 +020073 resp, body = self.get('os-hypervisors/%s/search' % hyper_name)
Lingxian Kong1629d5d2013-10-05 17:12:29 +080074 hypervisors = self._parse_array(etree.fromstring(body))
75 return resp, hypervisors