blob: f7d7b0ac01d388999905e25aa137f1f64ee63cb5 [file] [log] [blame]
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2#
3# Copyright 2013 IBM Corp.
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
17import urllib
18
19from lxml import etree
20from tempest.common.rest_client import RestClientXML
Lingxian Kong4b398fd2013-10-04 17:14:14 +080021from tempest.services.compute.xml.common import Document
22from tempest.services.compute.xml.common import Element
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080023from tempest.services.compute.xml.common import xml_to_json
24
25
26class HostsClientXML(RestClientXML):
27
28 def __init__(self, config, username, password, auth_url, tenant_name=None):
29 super(HostsClientXML, self).__init__(config, username, password,
30 auth_url, tenant_name)
31 self.service = self.config.compute.catalog_type
32
33 def list_hosts(self, params=None):
34 """Lists all hosts."""
35
36 url = 'os-hosts'
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
Zhu Zhuff150052013-09-17 17:48:39 +080044
45 def show_host_detail(self, hostname):
46 """Show detail information for the host."""
47
48 resp, body = self.get("os-hosts/%s" % str(hostname), self.headers)
49 node = etree.fromstring(body)
50 body = [xml_to_json(x) for x in node.getchildren()]
51 return resp, body
Lingxian Kong4b398fd2013-10-04 17:14:14 +080052
53 def update_host(self, hostname, status=None, maintenance_mode=None,
54 **kwargs):
55 """Update a host."""
56
57 request_body = Element(status=status,
58 maintenance_mode=maintenance_mode)
59 if kwargs:
60 for k, v in kwargs.iteritem():
61 request_body.add_attr(k, v)
62 resp, body = self.put("os-hosts/%s" % str(hostname),
63 str(Document(request_body)),
64 self.headers)
65 node = etree.fromstring(body)
66 body = [xml_to_json(x) for x in node.getchildren()]
67 return resp, body
68
69 def startup_host(self, hostname):
70 """Startup a host."""
71
72 resp, body = self.get("os-hosts/%s/startup" % str(hostname),
73 self.headers)
74 node = etree.fromstring(body)
75 body = [xml_to_json(x) for x in node.getchildren()]
76 return resp, body
77
78 def shutdown_host(self, hostname):
79 """Shutdown a host."""
80
81 resp, body = self.get("os-hosts/%s/shutdown" % str(hostname),
82 self.headers)
83 node = etree.fromstring(body)
84 body = [xml_to_json(x) for x in node.getchildren()]
85 return resp, body
86
87 def reboot_host(self, hostname):
88 """Reboot a host."""
89
90 resp, body = self.get("os-hosts/%s/reboot" % str(hostname),
91 self.headers)
92 node = etree.fromstring(body)
93 body = [xml_to_json(x) for x in node.getchildren()]
94 return resp, body