Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation |
| 2 | # Copyright 2013 IBM Corp. |
| 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | from oslo_serialization import jsonutils as json |
| 18 | from six.moves.urllib import parse as urllib |
| 19 | |
| 20 | from tempest.lib.api_schema.response.compute.v2_1 import services as schema |
Felipe Monteiro | fe399fd | 2017-05-29 21:46:44 +0100 | [diff] [blame] | 21 | from tempest.lib.api_schema.response.compute.v2_11 import services \ |
| 22 | as schemav211 |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 23 | from tempest.lib.common import rest_client |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 24 | from tempest.lib.services.compute import base_compute_client |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 25 | |
| 26 | |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 27 | class ServicesClient(base_compute_client.BaseComputeClient): |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 28 | |
Felipe Monteiro | fe399fd | 2017-05-29 21:46:44 +0100 | [diff] [blame] | 29 | schema_versions_info = [ |
| 30 | {'min': None, 'max': '2.10', 'schema': schema}, |
| 31 | {'min': '2.11', 'max': None, 'schema': schemav211}] |
| 32 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 33 | def list_services(self, **params): |
Lv Fumei | 7e32633 | 2016-07-08 15:18:03 +0800 | [diff] [blame] | 34 | """Lists all running Compute services for a tenant. |
| 35 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 36 | For a full list of available parameters, please refer to the official |
| 37 | API reference: |
zhufl | 4ffa4c1 | 2017-03-08 15:22:40 +0800 | [diff] [blame] | 38 | https://developer.openstack.org/api-ref/compute/#list-compute-services |
Lv Fumei | 7e32633 | 2016-07-08 15:18:03 +0800 | [diff] [blame] | 39 | """ |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 40 | url = 'os-services' |
| 41 | if params: |
| 42 | url += '?%s' % urllib.urlencode(params) |
| 43 | |
| 44 | resp, body = self.get(url) |
| 45 | body = json.loads(body) |
Felipe Monteiro | fe399fd | 2017-05-29 21:46:44 +0100 | [diff] [blame] | 46 | _schema = self.get_schema(self.schema_versions_info) |
| 47 | self.validate_response(_schema.list_services, resp, body) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 48 | return rest_client.ResponseBody(resp, body) |
| 49 | |
| 50 | def enable_service(self, **kwargs): |
| 51 | """Enable service on a host. |
| 52 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 53 | For a full list of available parameters, please refer to the official |
| 54 | API reference: |
zhufl | 4ffa4c1 | 2017-03-08 15:22:40 +0800 | [diff] [blame] | 55 | https://developer.openstack.org/api-ref/compute/#enable-scheduling-for-a-compute-service |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 56 | """ |
| 57 | post_body = json.dumps(kwargs) |
| 58 | resp, body = self.put('os-services/enable', post_body) |
| 59 | body = json.loads(body) |
| 60 | self.validate_response(schema.enable_disable_service, resp, body) |
| 61 | return rest_client.ResponseBody(resp, body) |
| 62 | |
| 63 | def disable_service(self, **kwargs): |
| 64 | """Disable service on a host. |
| 65 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 66 | For a full list of available parameters, please refer to the official |
| 67 | API reference: |
zhufl | 4ffa4c1 | 2017-03-08 15:22:40 +0800 | [diff] [blame] | 68 | https://developer.openstack.org/api-ref/compute/#disable-scheduling-for-a-compute-service |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 69 | """ |
| 70 | post_body = json.dumps(kwargs) |
| 71 | resp, body = self.put('os-services/disable', post_body) |
| 72 | body = json.loads(body) |
| 73 | self.validate_response(schema.enable_disable_service, resp, body) |
| 74 | return rest_client.ResponseBody(resp, body) |
Felipe Monteiro | fe399fd | 2017-05-29 21:46:44 +0100 | [diff] [blame] | 75 | |
| 76 | def disable_log_reason(self, **kwargs): |
| 77 | """Disables scheduling for a Compute service and logs reason. |
| 78 | |
| 79 | For a full list of available parameters, please refer to the official |
| 80 | API reference: |
| 81 | https://developer.openstack.org/api-ref/compute/#log-disabled-compute-service-information |
| 82 | """ |
| 83 | post_body = json.dumps(kwargs) |
| 84 | resp, body = self.put('os-services/disable-log-reason', post_body) |
| 85 | body = json.loads(body) |
| 86 | self.validate_response(schema.disable_log_reason, resp, body) |
| 87 | return rest_client.ResponseBody(resp, body) |
| 88 | |
| 89 | def update_forced_down(self, **kwargs): |
| 90 | """Set or unset ``forced_down`` flag for the service. |
| 91 | |
| 92 | For a full list of available parameters, please refer to the official |
| 93 | API reference: |
| 94 | https://developer.openstack.org/api-ref/compute/#update-forced-down |
| 95 | """ |
| 96 | post_body = json.dumps(kwargs) |
| 97 | resp, body = self.put('os-services/force-down', post_body) |
| 98 | body = json.loads(body) |
| 99 | # NOTE: Use schemav211.update_forced_down directly because there is no |
| 100 | # update_forced_down schema for <2.11. |
| 101 | self.validate_response(schemav211.update_forced_down, resp, body) |
| 102 | return rest_client.ResponseBody(resp, body) |