blob: e1e78d03fc6838095d31d05613fb287045913e03 [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
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080017import urllib
18
Leo Toyoda3ae31e12013-04-19 11:19:57 +090019from lxml import etree
Matthew Treinish684d8992014-01-30 16:27:40 +000020
vponomaryov960eeb42014-02-22 18:25:25 +020021from tempest.common import rest_client
Matthew Treinish28f164c2014-03-04 18:55:06 +000022from tempest.common import xml_utils
Matthew Treinish684d8992014-01-30 16:27:40 +000023from tempest import config
Leo Toyoda3ae31e12013-04-19 11:19:57 +090024
Matthew Treinish684d8992014-01-30 16:27:40 +000025CONF = config.CONF
26
Leo Toyoda3ae31e12013-04-19 11:19:57 +090027
vponomaryov960eeb42014-02-22 18:25:25 +020028class ServicesClientXML(rest_client.RestClient):
29 TYPE = "xml"
Leo Toyoda3ae31e12013-04-19 11:19:57 +090030
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000031 def __init__(self, auth_provider):
32 super(ServicesClientXML, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000033 self.service = CONF.compute.catalog_type
Leo Toyoda3ae31e12013-04-19 11:19:57 +090034
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080035 def list_services(self, params=None):
36 url = 'os-services'
37 if params:
38 url += '?%s' % urllib.urlencode(params)
39
vponomaryovf4c27f92014-02-18 10:56:42 +020040 resp, body = self.get(url)
Leo Toyoda3ae31e12013-04-19 11:19:57 +090041 node = etree.fromstring(body)
Matthew Treinish28f164c2014-03-04 18:55:06 +000042 body = [xml_utils.xml_to_json(x) for x in node.getchildren()]
Leo Toyoda3ae31e12013-04-19 11:19:57 +090043 return resp, body
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080044
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 Treinish28f164c2014-03-04 18:55:06 +000051 post_body = xml_utils.Element("service")
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080052 post_body.add_attr('binary', binary)
53 post_body.add_attr('host', host_name)
54
Matthew Treinish28f164c2014-03-04 18:55:06 +000055 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 Kund42c9912013-07-18 23:03:57 +080058 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 Treinish28f164c2014-03-04 18:55:06 +000066 post_body = xml_utils.Element("service")
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080067 post_body.add_attr('binary', binary)
68 post_body.add_attr('host', host_name)
69
Matthew Treinish28f164c2014-03-04 18:55:06 +000070 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 Kund42c9912013-07-18 23:03:57 +080073 return resp, body