Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 1 | # 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 | |
| 16 | from lxml import etree |
| 17 | |
| 18 | from tempest.common.rest_client import RestClientXML |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 19 | from tempest import config |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 20 | from tempest.services.compute.xml.common import xml_to_json |
| 21 | |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 22 | CONF = config.CONF |
| 23 | |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 24 | |
| 25 | class HypervisorClientXML(RestClientXML): |
| 26 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 27 | def __init__(self, auth_provider): |
| 28 | super(HypervisorClientXML, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 29 | self.service = CONF.compute.catalog_type |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 30 | |
| 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 Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 72 | |
| 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 |