blob: 8d73c37da4940579d057be081ae3d9172ae2911b [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
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080018import urllib
Leo Toyoda3ae31e12013-04-19 11:19:57 +090019
Marc Koderer6fbd74f2014-08-04 09:38:19 +020020from tempest.api_schema.response.compute import services as schema
Ken'ichi Ohmichiebf0f8c2014-12-24 03:47:35 +000021from tempest.services.compute.json import base
Leo Toyoda3ae31e12013-04-19 11:19:57 +090022
23
Ken'ichi Ohmichiebf0f8c2014-12-24 03:47:35 +000024class ServicesClientJSON(base.ComputeClient):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090025
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080026 def list_services(self, params=None):
27 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)
Leo Toyoda3ae31e12013-04-19 11:19:57 +090034 return resp, body['services']
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)
Ken'ichi Ohmichi26bcee62014-03-19 14:30:38 +090045 self.validate_response(schema.enable_service, resp, body)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080046 return resp, body['service']
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})
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)
57 return resp, body['service']