blob: 324041bef48c8f527099eb93d215740146988235 [file] [log] [blame]
Leo Toyoda3ae31e12013-04-19 11:19:57 +09001# Copyright 2013 NEC Corporation
Liu, Zhi Kund42c9912013-07-18 23:03:57 +08002# Copyright 2013 IBM Corp.
Leo Toyoda3ae31e12013-04-19 11:19:57 +09003# 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
17import json
Matthew Treinish89128142015-04-23 10:44:30 -040018
19from six.moves.urllib import parse as urllib
Leo Toyoda3ae31e12013-04-19 11:19:57 +090020
ghanshyam59869d02015-04-22 17:23:08 +090021from tempest.api_schema.response.compute.v2_1 import services as schema
David Kranz0a735172015-01-16 10:51:18 -050022from tempest.common import service_client
Leo Toyoda3ae31e12013-04-19 11:19:57 +090023
24
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000025class ServicesClient(service_client.ServiceClient):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090026
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000027 def list_services(self, **params):
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080028 url = 'os-services'
29 if params:
30 url += '?%s' % urllib.urlencode(params)
31
32 resp, body = self.get(url)
Leo Toyoda3ae31e12013-04-19 11:19:57 +090033 body = json.loads(body)
Chris Yeohc266b282014-03-13 18:19:00 +103034 self.validate_response(schema.list_services, resp, body)
David Kranz0a735172015-01-16 10:51:18 -050035 return service_client.ResponseBodyList(resp, body['services'])
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080036
37 def enable_service(self, host_name, binary):
38 """
39 Enable service on a host
40 host_name: Name of host
41 binary: Service binary
42 """
43 post_body = json.dumps({'binary': binary, 'host': host_name})
vponomaryovf4c27f92014-02-18 10:56:42 +020044 resp, body = self.put('os-services/enable', post_body)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080045 body = json.loads(body)
Ken'ichi Ohmichi26bcee62014-03-19 14:30:38 +090046 self.validate_response(schema.enable_service, resp, body)
David Kranz0a735172015-01-16 10:51:18 -050047 return service_client.ResponseBody(resp, body['service'])
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080048
49 def disable_service(self, host_name, binary):
50 """
51 Disable service on a host
52 host_name: Name of host
53 binary: Service binary
54 """
55 post_body = json.dumps({'binary': binary, 'host': host_name})
vponomaryovf4c27f92014-02-18 10:56:42 +020056 resp, body = self.put('os-services/disable', post_body)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080057 body = json.loads(body)
David Kranz0a735172015-01-16 10:51:18 -050058 return service_client.ResponseBody(resp, body['service'])