blob: f82a18fa3bd65e2e9a12e78457f66e4dac59ba87 [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
Matthew Treinish21905512015-07-13 10:33:35 -040017from oslo_serialization import jsonutils as json
Matthew Treinish89128142015-04-23 10:44:30 -040018from six.moves.urllib import parse as urllib
Leo Toyoda3ae31e12013-04-19 11:19:57 +090019
ghanshyam59869d02015-04-22 17:23:08 +090020from tempest.api_schema.response.compute.v2_1 import services as schema
David Kranz0a735172015-01-16 10:51:18 -050021from tempest.common import service_client
Leo Toyoda3ae31e12013-04-19 11:19:57 +090022
23
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000024class ServicesClient(service_client.ServiceClient):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090025
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000026 def list_services(self, **params):
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080027 url = 'os-services'
28 if params:
29 url += '?%s' % urllib.urlencode(params)
30
31 resp, body = self.get(url)
Leo Toyoda3ae31e12013-04-19 11:19:57 +090032 body = json.loads(body)
Chris Yeohc266b282014-03-13 18:19:00 +103033 self.validate_response(schema.list_services, resp, body)
ghanshyam0de02842015-08-24 17:47:41 +090034 return service_client.ResponseBody(resp, body)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080035
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})
vponomaryovf4c27f92014-02-18 10:56:42 +020043 resp, body = self.put('os-services/enable', post_body)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080044 body = json.loads(body)
ghanshyam7fb9c392015-09-18 09:51:17 +090045 self.validate_response(schema.enable_disable_service, resp, body)
ghanshyam0de02842015-08-24 17:47:41 +090046 return service_client.ResponseBody(resp, body)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080047
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})
vponomaryovf4c27f92014-02-18 10:56:42 +020055 resp, body = self.put('os-services/disable', post_body)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080056 body = json.loads(body)
ghanshyam7fb9c392015-09-18 09:51:17 +090057 self.validate_response(schema.enable_disable_service, resp, body)
ghanshyam0de02842015-08-24 17:47:41 +090058 return service_client.ResponseBody(resp, body)