blob: 22155a96e4b8bdffe330fce1aa6c48837b50a866 [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
19from tempest.lib.common import rest_client
20
21
22class ServicesClient(rest_client.RestClient):
jeremy.zhang408cf572018-05-28 17:09:10 +080023 """Client class to send CRUD Volume Services API requests"""
ghanshyamde676ba2018-02-19 06:20:00 +000024
25 def list_services(self, **params):
jeremy.zhang408cf572018-05-28 17:09:10 +080026 """List all Cinder services.
27
28 For a full list of available parameters, please refer to the official
29 API reference:
30 https://developer.openstack.org/api-ref/block-storage/v3/#list-all-cinder-services
31 """
ghanshyamde676ba2018-02-19 06:20:00 +000032 url = 'os-services'
33 if params:
34 url += '?%s' % urllib.urlencode(params)
35
36 resp, body = self.get(url)
37 body = json.loads(body)
38 self.expected_success(200, resp.status)
39 return rest_client.ResponseBody(resp, body)
jeremy.zhang408cf572018-05-28 17:09:10 +080040
41 def enable_service(self, **kwargs):
42 """Enable service on a host.
43
44 For a full list of available parameters, please refer to the official
45 API reference:
46 https://developer.openstack.org/api-ref/block-storage/v3/#enable-a-cinder-service
47 """
48 put_body = json.dumps(kwargs)
49 resp, body = self.put('os-services/enable', put_body)
50 body = json.loads(body)
51 self.expected_success(200, resp.status)
52 return rest_client.ResponseBody(resp, body)
53
54 def disable_service(self, **kwargs):
55 """Disable service on a host.
56
57 For a full list of available parameters, please refer to the official
58 API reference:
59 https://developer.openstack.org/api-ref/block-storage/v3/#disable-a-cinder-service
60 """
61 put_body = json.dumps(kwargs)
62 resp, body = self.put('os-services/disable', put_body)
63 body = json.loads(body)
64 self.expected_success(200, resp.status)
65 return rest_client.ResponseBody(resp, body)
66
67 def disable_log_reason(self, **kwargs):
68 """Disable scheduling for a volume service and log disabled reason.
69
70 For a full list of available parameters, please refer to the official
71 API reference:
72 https://developer.openstack.org/api-ref/block-storage/v3/#log-disabled-cinder-service-information
73 """
74 put_body = json.dumps(kwargs)
75 resp, body = self.put('os-services/disable-log-reason', put_body)
76 body = json.loads(body)
77 self.expected_success(200, resp.status)
78 return rest_client.ResponseBody(resp, body)
79
80 def freeze_host(self, **kwargs):
81 """Freeze a Cinder backend host.
82
83 For a full list of available parameters, please refer to the official
84 API reference:
85 https://developer.openstack.org/api-ref/block-storage/v3/#freeze-a-cinder-backend-host
86 """
87 put_body = json.dumps(kwargs)
88 resp, _ = self.put('os-services/freeze', put_body)
89 self.expected_success(200, resp.status)
90 return rest_client.ResponseBody(resp)
91
92 def thaw_host(self, **kwargs):
93 """Thaw a Cinder backend host.
94
95 For a full list of available parameters, please refer to the official
96 API reference:
97 https://developer.openstack.org/api-ref/block-storage/v3/#thaw-a-cinder-backend-host
98 """
99 put_body = json.dumps(kwargs)
100 resp, _ = self.put('os-services/thaw', put_body)
101 self.expected_success(200, resp.status)
102 return rest_client.ResponseBody(resp)