Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 2 | # Copyright 2013 IBM Corp. |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 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 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 17 | from oslo_serialization import jsonutils as json |
Matthew Treinish | 8912814 | 2015-04-23 10:44:30 -0400 | [diff] [blame] | 18 | from six.moves.urllib import parse as urllib |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 19 | |
ghanshyam | 59869d0 | 2015-04-22 17:23:08 +0900 | [diff] [blame] | 20 | from tempest.api_schema.response.compute.v2_1 import services as schema |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 21 | from tempest.common import service_client |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 22 | |
| 23 | |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 24 | class ServicesClient(service_client.ServiceClient): |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 25 | |
Ken'ichi Ohmichi | 118776d | 2015-07-01 08:15:00 +0000 | [diff] [blame] | 26 | def list_services(self, **params): |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 27 | url = 'os-services' |
| 28 | if params: |
| 29 | url += '?%s' % urllib.urlencode(params) |
| 30 | |
| 31 | resp, body = self.get(url) |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 32 | body = json.loads(body) |
Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 33 | self.validate_response(schema.list_services, resp, body) |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 34 | return service_client.ResponseBody(resp, body) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 35 | |
| 36 | def enable_service(self, host_name, binary): |
| 37 | """ |
| 38 | Enable service on a host |
| 39 | host_name: Name of host |
| 40 | binary: Service binary |
| 41 | """ |
| 42 | post_body = json.dumps({'binary': binary, 'host': host_name}) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 43 | resp, body = self.put('os-services/enable', post_body) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 44 | body = json.loads(body) |
ghanshyam | 7fb9c39 | 2015-09-18 09:51:17 +0900 | [diff] [blame] | 45 | self.validate_response(schema.enable_disable_service, resp, body) |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 46 | return service_client.ResponseBody(resp, body) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 47 | |
| 48 | def disable_service(self, host_name, binary): |
| 49 | """ |
| 50 | Disable service on a host |
| 51 | host_name: Name of host |
| 52 | binary: Service binary |
| 53 | """ |
| 54 | post_body = json.dumps({'binary': binary, 'host': host_name}) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 55 | resp, body = self.put('os-services/disable', post_body) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 56 | body = json.loads(body) |
ghanshyam | 7fb9c39 | 2015-09-18 09:51:17 +0900 | [diff] [blame] | 57 | self.validate_response(schema.enable_disable_service, resp, body) |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 58 | return service_client.ResponseBody(resp, body) |