ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 1 | # 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 | |
songwenping | 99d6e00 | 2021-01-05 03:07:46 +0000 | [diff] [blame] | 16 | from urllib import parse as urllib |
| 17 | |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 18 | from oslo_serialization import jsonutils as json |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 19 | |
zhufl | 38a78be | 2018-09-19 17:28:39 +0800 | [diff] [blame] | 20 | from tempest.lib.api_schema.response.volume import services as schema |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 21 | from tempest.lib.common import rest_client |
| 22 | |
| 23 | |
| 24 | class ServicesClient(rest_client.RestClient): |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 25 | """Client class to send CRUD Volume Services API requests""" |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 26 | |
| 27 | def list_services(self, **params): |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 28 | """List all Cinder services. |
| 29 | |
| 30 | For a full list of available parameters, please refer to the official |
| 31 | API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 32 | https://docs.openstack.org/api-ref/block-storage/v3/#list-all-cinder-services |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 33 | """ |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 34 | url = 'os-services' |
| 35 | if params: |
| 36 | url += '?%s' % urllib.urlencode(params) |
| 37 | |
| 38 | resp, body = self.get(url) |
| 39 | body = json.loads(body) |
zhufl | 38a78be | 2018-09-19 17:28:39 +0800 | [diff] [blame] | 40 | self.validate_response(schema.list_services, resp, body) |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 41 | return rest_client.ResponseBody(resp, body) |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 42 | |
| 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 Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 48 | https://docs.openstack.org/api-ref/block-storage/v3/#enable-a-cinder-service |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 49 | """ |
| 50 | put_body = json.dumps(kwargs) |
| 51 | resp, body = self.put('os-services/enable', put_body) |
| 52 | body = json.loads(body) |
zhufl | 38a78be | 2018-09-19 17:28:39 +0800 | [diff] [blame] | 53 | self.validate_response(schema.enable_service, resp, body) |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 54 | 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 Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 61 | https://docs.openstack.org/api-ref/block-storage/v3/#disable-a-cinder-service |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 62 | """ |
| 63 | put_body = json.dumps(kwargs) |
| 64 | resp, body = self.put('os-services/disable', put_body) |
| 65 | body = json.loads(body) |
zhufl | 38a78be | 2018-09-19 17:28:39 +0800 | [diff] [blame] | 66 | self.validate_response(schema.disable_service, resp, body) |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 67 | 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 Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 74 | https://docs.openstack.org/api-ref/block-storage/v3/#log-disabled-cinder-service-information |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 75 | """ |
| 76 | put_body = json.dumps(kwargs) |
| 77 | resp, body = self.put('os-services/disable-log-reason', put_body) |
| 78 | body = json.loads(body) |
zhufl | 38a78be | 2018-09-19 17:28:39 +0800 | [diff] [blame] | 79 | self.validate_response(schema.disable_log_reason, resp, body) |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 80 | 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 Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 87 | https://docs.openstack.org/api-ref/block-storage/v3/#freeze-a-cinder-backend-host |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 88 | """ |
| 89 | put_body = json.dumps(kwargs) |
zhufl | 38a78be | 2018-09-19 17:28:39 +0800 | [diff] [blame] | 90 | resp, body = self.put('os-services/freeze', put_body) |
| 91 | self.validate_response(schema.freeze_host, resp, body) |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 92 | 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 Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 99 | https://docs.openstack.org/api-ref/block-storage/v3/#thaw-a-cinder-backend-host |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 100 | """ |
| 101 | put_body = json.dumps(kwargs) |
zhufl | 38a78be | 2018-09-19 17:28:39 +0800 | [diff] [blame] | 102 | resp, body = self.put('os-services/thaw', put_body) |
| 103 | self.validate_response(schema.thaw_host, resp, body) |
jeremy.zhang | 408cf57 | 2018-05-28 17:09:10 +0800 | [diff] [blame] | 104 | return rest_client.ResponseBody(resp) |