Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 2 | # Copyright 2013 IBM Corp. |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 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 | |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 17 | import urllib |
| 18 | |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 19 | from lxml import etree |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 20 | |
vponomaryov | 960eeb4 | 2014-02-22 18:25:25 +0200 | [diff] [blame] | 21 | from tempest.common import rest_client |
Matthew Treinish | 28f164c | 2014-03-04 18:55:06 +0000 | [diff] [blame] | 22 | from tempest.common import xml_utils |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 23 | from tempest import config |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 24 | |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 25 | CONF = config.CONF |
| 26 | |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 27 | |
vponomaryov | 960eeb4 | 2014-02-22 18:25:25 +0200 | [diff] [blame] | 28 | class ServicesClientXML(rest_client.RestClient): |
| 29 | TYPE = "xml" |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 30 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 31 | def __init__(self, auth_provider): |
| 32 | super(ServicesClientXML, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 33 | self.service = CONF.compute.catalog_type |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 34 | |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 35 | def list_services(self, params=None): |
| 36 | url = 'os-services' |
| 37 | if params: |
| 38 | url += '?%s' % urllib.urlencode(params) |
| 39 | |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 40 | resp, body = self.get(url) |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 41 | node = etree.fromstring(body) |
Matthew Treinish | 28f164c | 2014-03-04 18:55:06 +0000 | [diff] [blame] | 42 | body = [xml_utils.xml_to_json(x) for x in node.getchildren()] |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 43 | return resp, body |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 44 | |
| 45 | def enable_service(self, host_name, binary): |
| 46 | """ |
| 47 | Enable service on a host |
| 48 | host_name: Name of host |
| 49 | binary: Service binary |
| 50 | """ |
Matthew Treinish | 28f164c | 2014-03-04 18:55:06 +0000 | [diff] [blame] | 51 | post_body = xml_utils.Element("service") |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 52 | post_body.add_attr('binary', binary) |
| 53 | post_body.add_attr('host', host_name) |
| 54 | |
Matthew Treinish | 28f164c | 2014-03-04 18:55:06 +0000 | [diff] [blame] | 55 | resp, body = self.put('os-services/enable', str( |
| 56 | xml_utils.Document(post_body))) |
| 57 | body = xml_utils.xml_to_json(etree.fromstring(body)) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 58 | return resp, body |
| 59 | |
| 60 | def disable_service(self, host_name, binary): |
| 61 | """ |
| 62 | Disable service on a host |
| 63 | host_name: Name of host |
| 64 | binary: Service binary |
| 65 | """ |
Matthew Treinish | 28f164c | 2014-03-04 18:55:06 +0000 | [diff] [blame] | 66 | post_body = xml_utils.Element("service") |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 67 | post_body.add_attr('binary', binary) |
| 68 | post_body.add_attr('host', host_name) |
| 69 | |
Matthew Treinish | 28f164c | 2014-03-04 18:55:06 +0000 | [diff] [blame] | 70 | resp, body = self.put('os-services/disable', str( |
| 71 | xml_utils.Document(post_body))) |
| 72 | body = xml_utils.xml_to_json(etree.fromstring(body)) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 73 | return resp, body |