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 | |
Marc Koderer | 6fbd74f | 2014-08-04 09:38:19 +0200 | [diff] [blame] | 18 | from tempest.api_schema.response.compute import hypervisors as common_schema |
| 19 | from tempest.api_schema.response.compute.v2 import hypervisors as v2schema |
Haiwei Xu | ab92462 | 2014-03-05 04:33:51 +0900 | [diff] [blame] | 20 | from tempest.common import rest_client |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 21 | from tempest import config |
| 22 | |
| 23 | CONF = config.CONF |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 24 | |
| 25 | |
Haiwei Xu | ab92462 | 2014-03-05 04:33:51 +0900 | [diff] [blame] | 26 | class HypervisorClientJSON(rest_client.RestClient): |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 27 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 28 | def __init__(self, auth_provider): |
| 29 | super(HypervisorClientJSON, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 30 | self.service = CONF.compute.catalog_type |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 31 | |
| 32 | def get_hypervisor_list(self): |
| 33 | """List hypervisors information.""" |
| 34 | resp, body = self.get('os-hypervisors') |
| 35 | body = json.loads(body) |
Ghanshyam | c7a0c7a | 2014-03-28 09:29:34 +0900 | [diff] [blame] | 36 | self.validate_response(common_schema.common_hypervisors_detail, |
| 37 | resp, body) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 38 | return resp, body['hypervisors'] |
| 39 | |
| 40 | def get_hypervisor_list_details(self): |
| 41 | """Show detailed hypervisors information.""" |
| 42 | resp, body = self.get('os-hypervisors/detail') |
| 43 | body = json.loads(body) |
Ghanshyam | 028044c | 2014-03-26 19:20:28 +0900 | [diff] [blame] | 44 | self.validate_response(common_schema.common_list_hypervisors_detail, |
| 45 | resp, body) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 46 | return resp, body['hypervisors'] |
| 47 | |
| 48 | def get_hypervisor_show_details(self, hyper_id): |
| 49 | """Display the details of the specified hypervisor.""" |
| 50 | resp, body = self.get('os-hypervisors/%s' % hyper_id) |
| 51 | body = json.loads(body) |
Ghanshyam | 3495c4f | 2014-03-24 09:22:57 +0900 | [diff] [blame] | 52 | self.validate_response(common_schema.common_show_hypervisor, |
| 53 | resp, body) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 54 | return resp, body['hypervisor'] |
| 55 | |
| 56 | def get_hypervisor_servers(self, hyper_name): |
| 57 | """List instances belonging to the specified hypervisor.""" |
| 58 | resp, body = self.get('os-hypervisors/%s/servers' % hyper_name) |
| 59 | body = json.loads(body) |
Ghanshyam | 8676fa6 | 2014-03-26 20:00:37 +0900 | [diff] [blame] | 60 | self.validate_response(v2schema.hypervisors_servers, resp, body) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 61 | return resp, body['hypervisors'] |
| 62 | |
| 63 | def get_hypervisor_stats(self): |
| 64 | """Get hypervisor statistics over all compute nodes.""" |
| 65 | resp, body = self.get('os-hypervisors/statistics') |
| 66 | body = json.loads(body) |
Ghanshyam | 1002a03 | 2014-03-26 20:48:10 +0900 | [diff] [blame] | 67 | self.validate_response(common_schema.hypervisor_statistics, resp, body) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 68 | return resp, body['hypervisor_statistics'] |
| 69 | |
| 70 | def get_hypervisor_uptime(self, hyper_id): |
| 71 | """Display the uptime of the specified hypervisor.""" |
| 72 | resp, body = self.get('os-hypervisors/%s/uptime' % hyper_id) |
| 73 | body = json.loads(body) |
Ghanshyam | dd8ae35 | 2014-03-28 09:48:38 +0900 | [diff] [blame] | 74 | self.validate_response(common_schema.hypervisor_uptime, resp, body) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 75 | return resp, body['hypervisor'] |
Lingxian Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 76 | |
| 77 | def search_hypervisor(self, hyper_name): |
| 78 | """Search specified hypervisor.""" |
| 79 | resp, body = self.get('os-hypervisors/%s/search' % hyper_name) |
| 80 | body = json.loads(body) |
Ghanshyam | c7a0c7a | 2014-03-28 09:29:34 +0900 | [diff] [blame] | 81 | self.validate_response(common_schema.common_hypervisors_detail, |
| 82 | resp, body) |
Lingxian Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 83 | return resp, body['hypervisors'] |