blob: 019a85283a4e2a12e4234509d0024fe4a0d630a5 [file] [log] [blame]
ghanshyamde676ba2018-02-19 06:20:00 +00001# Copyright 2014 OpenStack Foundation
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
17from six.moves.urllib import parse as urllib
18
zhufl2f1806a2018-09-19 11:47:41 +080019from tempest.lib.api_schema.response.volume import hosts as schema
ghanshyamde676ba2018-02-19 06:20:00 +000020from tempest.lib.common import rest_client
21
22
23class HostsClient(rest_client.RestClient):
24 """Client class to send CRUD Volume API requests"""
25
26 def list_hosts(self, **params):
27 """Lists all hosts.
28
29 For a full list of available parameters, please refer to the official
30 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020031 https://docs.openstack.org/api-ref/block-storage/v3/index.html#list-all-hosts-for-a-project
ghanshyamde676ba2018-02-19 06:20:00 +000032 """
33 url = 'os-hosts'
34 if params:
35 url += '?%s' % urllib.urlencode(params)
36
37 resp, body = self.get(url)
38 body = json.loads(body)
zhufl2f1806a2018-09-19 11:47:41 +080039 self.validate_response(schema.list_hosts, resp, body)
ghanshyamde676ba2018-02-19 06:20:00 +000040 return rest_client.ResponseBody(resp, body)
41
42 def show_host(self, host_name):
43 """Show host details."""
44 url = 'os-hosts/%s' % host_name
45 resp, body = self.get(url)
ghanshyamde676ba2018-02-19 06:20:00 +000046 body = json.loads(body)
zhufl2f1806a2018-09-19 11:47:41 +080047 self.validate_response(schema.show_host, resp, body)
ghanshyamde676ba2018-02-19 06:20:00 +000048 return rest_client.ResponseBody(resp, body)