blob: 23c304e836349a392c6f626e9b0e431e3a6d1175 [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# 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 oslo_serialization import jsonutils as json
17
18from tempest.lib.api_schema.response.compute.v2_1 import hypervisors as schema
19from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090020from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050021
22
Ghanshyamee9af302016-02-25 06:12:43 +090023class HypervisorClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050024
25 def list_hypervisors(self, detail=False):
26 """List hypervisors information."""
27 url = 'os-hypervisors'
28 _schema = schema.list_search_hypervisors
29 if detail:
30 url += '/detail'
31 _schema = schema.list_hypervisors_detail
32
33 resp, body = self.get(url)
34 body = json.loads(body)
35 self.validate_response(_schema, resp, body)
36 return rest_client.ResponseBody(resp, body)
37
38 def show_hypervisor(self, hypervisor_id):
39 """Display the details of the specified hypervisor."""
40 resp, body = self.get('os-hypervisors/%s' % hypervisor_id)
41 body = json.loads(body)
42 self.validate_response(schema.get_hypervisor, resp, body)
43 return rest_client.ResponseBody(resp, body)
44
45 def list_servers_on_hypervisor(self, hypervisor_name):
46 """List instances belonging to the specified hypervisor."""
47 resp, body = self.get('os-hypervisors/%s/servers' % hypervisor_name)
48 body = json.loads(body)
49 self.validate_response(schema.get_hypervisors_servers, resp, body)
50 return rest_client.ResponseBody(resp, body)
51
52 def show_hypervisor_statistics(self):
53 """Get hypervisor statistics over all compute nodes."""
54 resp, body = self.get('os-hypervisors/statistics')
55 body = json.loads(body)
56 self.validate_response(schema.get_hypervisor_statistics, resp, body)
57 return rest_client.ResponseBody(resp, body)
58
59 def show_hypervisor_uptime(self, hypervisor_id):
60 """Display the uptime of the specified hypervisor."""
61 resp, body = self.get('os-hypervisors/%s/uptime' % hypervisor_id)
62 body = json.loads(body)
63 self.validate_response(schema.get_hypervisor_uptime, resp, body)
64 return rest_client.ResponseBody(resp, body)
65
Ken'ichi Ohmichi12b28e92016-04-06 10:43:51 -070066 def search_hypervisor(self, hypervisor_name): # noqa
67 # NOTE: This noqa is for passing T110 check and we cannot rename
68 # to keep backwards compatibility.
Matthew Treinish9e26ca82016-02-23 11:43:20 -050069 """Search specified hypervisor."""
70 resp, body = self.get('os-hypervisors/%s/search' % hypervisor_name)
71 body = json.loads(body)
72 self.validate_response(schema.list_search_hypervisors, resp, body)
73 return rest_client.ResponseBody(resp, body)