blob: e20dfde6f97f30899afb3aad1b1def4e4795c6ce [file] [log] [blame]
ivan-zhua2c9cd52013-08-20 20:01:44 +08001# 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
17import json
18import urllib
19
20from tempest.common.rest_client import RestClient
Matthew Treinish684d8992014-01-30 16:27:40 +000021from tempest import config
22
23CONF = config.CONF
ivan-zhua2c9cd52013-08-20 20:01:44 +080024
25
ivan-zhu5c86ae62013-08-20 21:09:01 +080026class ServicesV3ClientJSON(RestClient):
ivan-zhua2c9cd52013-08-20 20:01:44 +080027
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000028 def __init__(self, auth_provider):
29 super(ServicesV3ClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000030 self.service = CONF.compute.catalog_v3_type
ivan-zhua2c9cd52013-08-20 20:01:44 +080031
32 def list_services(self, params=None):
33 url = 'os-services'
34 if params:
35 url += '?%s' % urllib.urlencode(params)
36
37 resp, body = self.get(url)
38 body = json.loads(body)
39 return resp, body['services']
40
41 def enable_service(self, host_name, binary):
42 """
43 Enable service on a host
44 host_name: Name of host
45 binary: Service binary
46 """
ivan-zhu5c86ae62013-08-20 21:09:01 +080047 post_body = json.dumps({
48 'service': {
49 'binary': binary,
50 'host': host_name
51 }
52 })
vponomaryovf4c27f92014-02-18 10:56:42 +020053 resp, body = self.put('os-services/enable', post_body)
ivan-zhua2c9cd52013-08-20 20:01:44 +080054 body = json.loads(body)
55 return resp, body['service']
56
57 def disable_service(self, host_name, binary):
58 """
59 Disable service on a host
60 host_name: Name of host
61 binary: Service binary
62 """
ivan-zhu5c86ae62013-08-20 21:09:01 +080063 post_body = json.dumps({
64 'service': {
65 'binary': binary,
66 'host': host_name
67 }
68 })
vponomaryovf4c27f92014-02-18 10:56:42 +020069 resp, body = self.put('os-services/disable', post_body)
ivan-zhua2c9cd52013-08-20 20:01:44 +080070 body = json.loads(body)
71 return resp, body['service']