blob: bfc824d23cd6a39b9def27eea08caa33a5b1a80d [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
Leo Toyoda3ae31e12013-04-19 11:19:57 +090021from tempest.common.rest_client import RestClientXML
Matthew Treinish684d8992014-01-30 16:27:40 +000022from tempest import config
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080023from tempest.services.compute.xml.common import Document
24from tempest.services.compute.xml.common import Element
Leo Toyoda3ae31e12013-04-19 11:19:57 +090025from tempest.services.compute.xml.common import xml_to_json
26
Matthew Treinish684d8992014-01-30 16:27:40 +000027CONF = config.CONF
28
Leo Toyoda3ae31e12013-04-19 11:19:57 +090029
30class ServicesClientXML(RestClientXML):
31
Matthew Treinish684d8992014-01-30 16:27:40 +000032 def __init__(self, username, password, auth_url, tenant_name=None):
33 super(ServicesClientXML, self).__init__(username, password,
Leo Toyoda3ae31e12013-04-19 11:19:57 +090034 auth_url, tenant_name)
Matthew Treinish684d8992014-01-30 16:27:40 +000035 self.service = CONF.compute.catalog_type
Leo Toyoda3ae31e12013-04-19 11:19:57 +090036
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080037 def list_services(self, params=None):
38 url = 'os-services'
39 if params:
40 url += '?%s' % urllib.urlencode(params)
41
42 resp, body = self.get(url, self.headers)
Leo Toyoda3ae31e12013-04-19 11:19:57 +090043 node = etree.fromstring(body)
44 body = [xml_to_json(x) for x in node.getchildren()]
45 return resp, body
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080046
47 def enable_service(self, host_name, binary):
48 """
49 Enable service on a host
50 host_name: Name of host
51 binary: Service binary
52 """
53 post_body = Element("service")
54 post_body.add_attr('binary', binary)
55 post_body.add_attr('host', host_name)
56
57 resp, body = self.put('os-services/enable', str(Document(post_body)),
58 self.headers)
59 body = xml_to_json(etree.fromstring(body))
60 return resp, body
61
62 def disable_service(self, host_name, binary):
63 """
64 Disable service on a host
65 host_name: Name of host
66 binary: Service binary
67 """
68 post_body = Element("service")
69 post_body.add_attr('binary', binary)
70 post_body.add_attr('host', host_name)
71
72 resp, body = self.put('os-services/disable', str(Document(post_body)),
73 self.headers)
74 body = xml_to_json(etree.fromstring(body))
75 return resp, body