blob: 41564e5ab19883fdfef7ad126164b239257a6877 [file] [log] [blame]
ivan-zhua2c9cd52013-08-20 20:01:44 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 NEC Corporation
4# Copyright 2013 IBM Corp.
5# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
19import json
20import urllib
21
22from tempest.common.rest_client import RestClient
23
24
ivan-zhu5c86ae62013-08-20 21:09:01 +080025class ServicesV3ClientJSON(RestClient):
ivan-zhua2c9cd52013-08-20 20:01:44 +080026
27 def __init__(self, config, username, password, auth_url, tenant_name=None):
ivan-zhu5c86ae62013-08-20 21:09:01 +080028 super(ServicesV3ClientJSON, self).__init__(config, username, password,
29 auth_url, tenant_name)
30 self.service = self.config.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 })
ivan-zhua2c9cd52013-08-20 20:01:44 +080053 resp, body = self.put('os-services/enable', post_body, self.headers)
54 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 })
ivan-zhua2c9cd52013-08-20 20:01:44 +080069 resp, body = self.put('os-services/disable', post_body, self.headers)
70 body = json.loads(body)
71 return resp, body['service']