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 | import json |
| 17 | |
| 18 | from tempest.common.rest_client import RestClient |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 19 | from tempest import config |
| 20 | |
| 21 | CONF = config.CONF |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class HypervisorClientJSON(RestClient): |
| 25 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 26 | def __init__(self, auth_provider): |
| 27 | super(HypervisorClientJSON, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 28 | self.service = CONF.compute.catalog_type |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 29 | |
| 30 | def get_hypervisor_list(self): |
| 31 | """List hypervisors information.""" |
| 32 | resp, body = self.get('os-hypervisors') |
| 33 | body = json.loads(body) |
| 34 | return resp, body['hypervisors'] |
| 35 | |
| 36 | def get_hypervisor_list_details(self): |
| 37 | """Show detailed hypervisors information.""" |
| 38 | resp, body = self.get('os-hypervisors/detail') |
| 39 | body = json.loads(body) |
| 40 | return resp, body['hypervisors'] |
| 41 | |
| 42 | def get_hypervisor_show_details(self, hyper_id): |
| 43 | """Display the details of the specified hypervisor.""" |
| 44 | resp, body = self.get('os-hypervisors/%s' % hyper_id) |
| 45 | body = json.loads(body) |
| 46 | return resp, body['hypervisor'] |
| 47 | |
| 48 | def get_hypervisor_servers(self, hyper_name): |
| 49 | """List instances belonging to the specified hypervisor.""" |
| 50 | resp, body = self.get('os-hypervisors/%s/servers' % hyper_name) |
| 51 | body = json.loads(body) |
| 52 | return resp, body['hypervisors'] |
| 53 | |
| 54 | def get_hypervisor_stats(self): |
| 55 | """Get hypervisor statistics over all compute nodes.""" |
| 56 | resp, body = self.get('os-hypervisors/statistics') |
| 57 | body = json.loads(body) |
| 58 | return resp, body['hypervisor_statistics'] |
| 59 | |
| 60 | def get_hypervisor_uptime(self, hyper_id): |
| 61 | """Display the uptime of the specified hypervisor.""" |
| 62 | resp, body = self.get('os-hypervisors/%s/uptime' % hyper_id) |
| 63 | body = json.loads(body) |
| 64 | return resp, body['hypervisor'] |
Lingxian Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 65 | |
| 66 | def search_hypervisor(self, hyper_name): |
| 67 | """Search specified hypervisor.""" |
| 68 | resp, body = self.get('os-hypervisors/%s/search' % hyper_name) |
| 69 | body = json.loads(body) |
| 70 | return resp, body['hypervisors'] |