blob: ef0e83a5d75d223d7f7db4c659a765d7a9288bd3 [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
16import json
17
Ghanshyam1002a032014-03-26 20:48:10 +090018from tempest.api_schema.compute import hypervisors as common_schema
Ghanshyam8676fa62014-03-26 20:00:37 +090019from tempest.api_schema.compute.v2 import hypervisors as v2schema
Haiwei Xuab924622014-03-05 04:33:51 +090020from tempest.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000021from tempest import config
22
23CONF = config.CONF
Tony Yang3d5f1632013-06-06 14:17:57 +080024
25
Haiwei Xuab924622014-03-05 04:33:51 +090026class HypervisorClientJSON(rest_client.RestClient):
Tony Yang3d5f1632013-06-06 14:17:57 +080027
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000028 def __init__(self, auth_provider):
29 super(HypervisorClientJSON, 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 get_hypervisor_list(self):
33 """List hypervisors information."""
34 resp, body = self.get('os-hypervisors')
35 body = json.loads(body)
36 return resp, body['hypervisors']
37
38 def get_hypervisor_list_details(self):
39 """Show detailed hypervisors information."""
40 resp, body = self.get('os-hypervisors/detail')
41 body = json.loads(body)
Ghanshyam028044c2014-03-26 19:20:28 +090042 self.validate_response(common_schema.common_list_hypervisors_detail,
43 resp, body)
Tony Yang3d5f1632013-06-06 14:17:57 +080044 return resp, body['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 body = json.loads(body)
Ghanshyam3495c4f2014-03-24 09:22:57 +090050 self.validate_response(common_schema.common_show_hypervisor,
51 resp, body)
Tony Yang3d5f1632013-06-06 14:17:57 +080052 return resp, body['hypervisor']
53
54 def get_hypervisor_servers(self, hyper_name):
55 """List instances belonging to the specified hypervisor."""
56 resp, body = self.get('os-hypervisors/%s/servers' % hyper_name)
57 body = json.loads(body)
Ghanshyam8676fa62014-03-26 20:00:37 +090058 self.validate_response(v2schema.hypervisors_servers, resp, body)
Tony Yang3d5f1632013-06-06 14:17:57 +080059 return resp, body['hypervisors']
60
61 def get_hypervisor_stats(self):
62 """Get hypervisor statistics over all compute nodes."""
63 resp, body = self.get('os-hypervisors/statistics')
64 body = json.loads(body)
Ghanshyam1002a032014-03-26 20:48:10 +090065 self.validate_response(common_schema.hypervisor_statistics, resp, body)
Tony Yang3d5f1632013-06-06 14:17:57 +080066 return resp, body['hypervisor_statistics']
67
68 def get_hypervisor_uptime(self, hyper_id):
69 """Display the uptime of the specified hypervisor."""
70 resp, body = self.get('os-hypervisors/%s/uptime' % hyper_id)
71 body = json.loads(body)
Ghanshyamdd8ae352014-03-28 09:48:38 +090072 self.validate_response(common_schema.hypervisor_uptime, resp, body)
Tony Yang3d5f1632013-06-06 14:17:57 +080073 return resp, body['hypervisor']
Lingxian Kong1629d5d2013-10-05 17:12:29 +080074
75 def search_hypervisor(self, hyper_name):
76 """Search specified hypervisor."""
77 resp, body = self.get('os-hypervisors/%s/search' % hyper_name)
78 body = json.loads(body)
79 return resp, body['hypervisors']