ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 1 | # 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 | |
| 19 | import json |
| 20 | import urllib |
| 21 | |
| 22 | from tempest.common.rest_client import RestClient |
| 23 | |
| 24 | |
ivan-zhu | 5c86ae6 | 2013-08-20 21:09:01 +0800 | [diff] [blame] | 25 | class ServicesV3ClientJSON(RestClient): |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 26 | |
| 27 | def __init__(self, config, username, password, auth_url, tenant_name=None): |
ivan-zhu | 5c86ae6 | 2013-08-20 21:09:01 +0800 | [diff] [blame] | 28 | super(ServicesV3ClientJSON, self).__init__(config, username, password, |
| 29 | auth_url, tenant_name) |
| 30 | self.service = self.config.compute.catalog_v3_type |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 31 | |
| 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-zhu | 5c86ae6 | 2013-08-20 21:09:01 +0800 | [diff] [blame] | 47 | post_body = json.dumps({ |
| 48 | 'service': { |
| 49 | 'binary': binary, |
| 50 | 'host': host_name |
| 51 | } |
| 52 | }) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 53 | 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-zhu | 5c86ae6 | 2013-08-20 21:09:01 +0800 | [diff] [blame] | 63 | post_body = json.dumps({ |
| 64 | 'service': { |
| 65 | 'binary': binary, |
| 66 | 'host': host_name |
| 67 | } |
| 68 | }) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 69 | resp, body = self.put('os-services/disable', post_body, self.headers) |
| 70 | body = json.loads(body) |
| 71 | return resp, body['service'] |