blob: 4672da8c8c4cab31ee68403aa6d104a6585e316f [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
songwenping99d6e002021-01-05 03:07:46 +000016from urllib import parse as urllib
17
ghanshyamde676ba2018-02-19 06:20:00 +000018from oslo_serialization import jsonutils as json
ghanshyamde676ba2018-02-19 06:20:00 +000019
zhufl38a78be2018-09-19 17:28:39 +080020from tempest.lib.api_schema.response.volume import services as schema
ghanshyamde676ba2018-02-19 06:20:00 +000021from tempest.lib.common import rest_client
22
23
24class ServicesClient(rest_client.RestClient):
jeremy.zhang408cf572018-05-28 17:09:10 +080025 """Client class to send CRUD Volume Services API requests"""
ghanshyamde676ba2018-02-19 06:20:00 +000026
27 def list_services(self, **params):
jeremy.zhang408cf572018-05-28 17:09:10 +080028 """List all Cinder services.
29
30 For a full list of available parameters, please refer to the official
31 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020032 https://docs.openstack.org/api-ref/block-storage/v3/#list-all-cinder-services
jeremy.zhang408cf572018-05-28 17:09:10 +080033 """
ghanshyamde676ba2018-02-19 06:20:00 +000034 url = 'os-services'
35 if params:
36 url += '?%s' % urllib.urlencode(params)
37
38 resp, body = self.get(url)
39 body = json.loads(body)
zhufl38a78be2018-09-19 17:28:39 +080040 self.validate_response(schema.list_services, resp, body)
ghanshyamde676ba2018-02-19 06:20:00 +000041 return rest_client.ResponseBody(resp, body)
jeremy.zhang408cf572018-05-28 17:09:10 +080042
43 def enable_service(self, **kwargs):
44 """Enable service on a host.
45
46 For a full list of available parameters, please refer to the official
47 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020048 https://docs.openstack.org/api-ref/block-storage/v3/#enable-a-cinder-service
jeremy.zhang408cf572018-05-28 17:09:10 +080049 """
50 put_body = json.dumps(kwargs)
51 resp, body = self.put('os-services/enable', put_body)
52 body = json.loads(body)
zhufl38a78be2018-09-19 17:28:39 +080053 self.validate_response(schema.enable_service, resp, body)
jeremy.zhang408cf572018-05-28 17:09:10 +080054 return rest_client.ResponseBody(resp, body)
55
56 def disable_service(self, **kwargs):
57 """Disable service on a host.
58
59 For a full list of available parameters, please refer to the official
60 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020061 https://docs.openstack.org/api-ref/block-storage/v3/#disable-a-cinder-service
jeremy.zhang408cf572018-05-28 17:09:10 +080062 """
63 put_body = json.dumps(kwargs)
64 resp, body = self.put('os-services/disable', put_body)
65 body = json.loads(body)
zhufl38a78be2018-09-19 17:28:39 +080066 self.validate_response(schema.disable_service, resp, body)
jeremy.zhang408cf572018-05-28 17:09:10 +080067 return rest_client.ResponseBody(resp, body)
68
69 def disable_log_reason(self, **kwargs):
70 """Disable scheduling for a volume service and log disabled reason.
71
72 For a full list of available parameters, please refer to the official
73 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020074 https://docs.openstack.org/api-ref/block-storage/v3/#log-disabled-cinder-service-information
jeremy.zhang408cf572018-05-28 17:09:10 +080075 """
76 put_body = json.dumps(kwargs)
77 resp, body = self.put('os-services/disable-log-reason', put_body)
78 body = json.loads(body)
zhufl38a78be2018-09-19 17:28:39 +080079 self.validate_response(schema.disable_log_reason, resp, body)
jeremy.zhang408cf572018-05-28 17:09:10 +080080 return rest_client.ResponseBody(resp, body)
81
82 def freeze_host(self, **kwargs):
83 """Freeze a Cinder backend host.
84
85 For a full list of available parameters, please refer to the official
86 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020087 https://docs.openstack.org/api-ref/block-storage/v3/#freeze-a-cinder-backend-host
jeremy.zhang408cf572018-05-28 17:09:10 +080088 """
89 put_body = json.dumps(kwargs)
zhufl38a78be2018-09-19 17:28:39 +080090 resp, body = self.put('os-services/freeze', put_body)
91 self.validate_response(schema.freeze_host, resp, body)
jeremy.zhang408cf572018-05-28 17:09:10 +080092 return rest_client.ResponseBody(resp)
93
94 def thaw_host(self, **kwargs):
95 """Thaw a Cinder backend host.
96
97 For a full list of available parameters, please refer to the official
98 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020099 https://docs.openstack.org/api-ref/block-storage/v3/#thaw-a-cinder-backend-host
jeremy.zhang408cf572018-05-28 17:09:10 +0800100 """
101 put_body = json.dumps(kwargs)
zhufl38a78be2018-09-19 17:28:39 +0800102 resp, body = self.put('os-services/thaw', put_body)
103 self.validate_response(schema.thaw_host, resp, body)
jeremy.zhang408cf572018-05-28 17:09:10 +0800104 return rest_client.ResponseBody(resp)