blob: 7829e5a31053ddac80bae37aad17f42f964a2e4f [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
20from tempest.common.rest_client import RestClient
21
22
23class ServicesClientJSON(RestClient):
24
25 def __init__(self, config, username, password, auth_url, tenant_name=None):
26 super(ServicesClientJSON, self).__init__(config, username, password,
27 auth_url, tenant_name)
28 self.service = self.config.compute.catalog_type
29
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080030 def list_services(self, params=None):
31 url = 'os-services'
32 if params:
33 url += '?%s' % urllib.urlencode(params)
34
35 resp, body = self.get(url)
Leo Toyoda3ae31e12013-04-19 11:19:57 +090036 body = json.loads(body)
37 return resp, body['services']
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080038
39 def enable_service(self, host_name, binary):
40 """
41 Enable service on a host
42 host_name: Name of host
43 binary: Service binary
44 """
45 post_body = json.dumps({'binary': binary, 'host': host_name})
46 resp, body = self.put('os-services/enable', post_body, self.headers)
47 body = json.loads(body)
48 return resp, body['service']
49
50 def disable_service(self, host_name, binary):
51 """
52 Disable service on a host
53 host_name: Name of host
54 binary: Service binary
55 """
56 post_body = json.dumps({'binary': binary, 'host': host_name})
57 resp, body = self.put('os-services/disable', post_body, self.headers)
58 body = json.loads(body)
59 return resp, body['service']