blob: ac304e2b22eb3dff0925bd3322caa34abae39a75 [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 urllib
20
21from lxml import etree
22from tempest.common.rest_client import RestClientXML
23from tempest.services.compute.xml.common import Document
24from tempest.services.compute.xml.common import Element
25from tempest.services.compute.xml.common import xml_to_json
26
27
28class ServicesClientXML(RestClientXML):
29
30 def __init__(self, config, username, password, auth_url, tenant_name=None):
31 super(ServicesClientXML, self).__init__(config, username, password,
32 auth_url, tenant_name)
33 self.service = self.config.compute.catalog_type
34
35 def list_services(self, params=None):
36 url = 'os-services'
37 if params:
38 url += '?%s' % urllib.urlencode(params)
39
40 resp, body = self.get(url, self.headers)
41 node = etree.fromstring(body)
42 body = [xml_to_json(x) for x in node.getchildren()]
43 return resp, body
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 """
51 post_body = Element("service")
52 post_body.add_attr('binary', binary)
53 post_body.add_attr('host', host_name)
54
55 resp, body = self.put('os-services/enable', str(Document(post_body)),
56 self.headers)
57 body = xml_to_json(etree.fromstring(body))
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 """
66 post_body = Element("service")
67 post_body.add_attr('binary', binary)
68 post_body.add_attr('host', host_name)
69
70 resp, body = self.put('os-services/disable', str(Document(post_body)),
71 self.headers)
72 body = xml_to_json(etree.fromstring(body))
73 return resp, body