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 |
| 21 | from tempest.lib.common import rest_client |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 22 | from tempest.lib.services.compute import base_compute_client |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 23 | |
| 24 | |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 25 | class ServicesClient(base_compute_client.BaseComputeClient): |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 26 | |
| 27 | def list_services(self, **params): |
Lv Fumei | 7e32633 | 2016-07-08 15:18:03 +0800 | [diff] [blame] | 28 | """Lists all running Compute services for a tenant. |
| 29 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 30 | For a full list of available parameters, please refer to the official |
| 31 | API reference: |
zhufl | 4ffa4c1 | 2017-03-08 15:22:40 +0800 | [diff] [blame^] | 32 | https://developer.openstack.org/api-ref/compute/#list-compute-services |
Lv Fumei | 7e32633 | 2016-07-08 15:18:03 +0800 | [diff] [blame] | 33 | """ |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [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) |
| 40 | self.validate_response(schema.list_services, resp, body) |
| 41 | return rest_client.ResponseBody(resp, body) |
| 42 | |
| 43 | def enable_service(self, **kwargs): |
| 44 | """Enable service on a host. |
| 45 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 46 | For a full list of available parameters, please refer to the official |
| 47 | API reference: |
zhufl | 4ffa4c1 | 2017-03-08 15:22:40 +0800 | [diff] [blame^] | 48 | 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] | 49 | """ |
| 50 | post_body = json.dumps(kwargs) |
| 51 | resp, body = self.put('os-services/enable', post_body) |
| 52 | body = json.loads(body) |
| 53 | self.validate_response(schema.enable_disable_service, resp, body) |
| 54 | return rest_client.ResponseBody(resp, body) |
| 55 | |
| 56 | def disable_service(self, **kwargs): |
| 57 | """Disable service on a host. |
| 58 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 59 | For a full list of available parameters, please refer to the official |
| 60 | API reference: |
zhufl | 4ffa4c1 | 2017-03-08 15:22:40 +0800 | [diff] [blame^] | 61 | 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] | 62 | """ |
| 63 | post_body = json.dumps(kwargs) |
| 64 | resp, body = self.put('os-services/disable', post_body) |
| 65 | body = json.loads(body) |
| 66 | self.validate_response(schema.enable_disable_service, resp, body) |
| 67 | return rest_client.ResponseBody(resp, body) |