blob: 669bf59ab4c570501a5ec899c08a0815a5e4b147 [file] [log] [blame]
ivan-zhu8577cb12013-08-20 14:38:36 +08001# Copyright 2013 IBM Corp.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import json
16import urllib
17
18from tempest.common.rest_client import RestClient
19
20
ivan-zhu00fe64f2013-08-20 19:35:51 +080021class HostsV3ClientJSON(RestClient):
ivan-zhu8577cb12013-08-20 14:38:36 +080022
23 def __init__(self, config, username, password, auth_url, tenant_name=None):
ivan-zhu00fe64f2013-08-20 19:35:51 +080024 super(HostsV3ClientJSON, self).__init__(config, username, password,
25 auth_url, tenant_name)
26 self.service = self.config.compute.catalog_v3_type
ivan-zhu8577cb12013-08-20 14:38:36 +080027
28 def list_hosts(self, params=None):
29 """Lists all hosts."""
30
31 url = 'os-hosts'
32 if params:
33 url += '?%s' % urllib.urlencode(params)
34
35 resp, body = self.get(url)
36 body = json.loads(body)
37 return resp, body['hosts']
38
39 def show_host_detail(self, hostname):
40 """Show detail information for the host."""
41
42 resp, body = self.get("os-hosts/%s" % str(hostname))
43 body = json.loads(body)
44 return resp, body['host']
45
46 def update_host(self, hostname, **kwargs):
47 """Update a host."""
48
49 request_body = {
50 'status': None,
51 'maintenance_mode': None,
52 }
53 request_body.update(**kwargs)
ivan-zhu00fe64f2013-08-20 19:35:51 +080054 request_body = json.dumps({'host': request_body})
ivan-zhu8577cb12013-08-20 14:38:36 +080055
56 resp, body = self.put("os-hosts/%s" % str(hostname), request_body,
57 self.headers)
58 body = json.loads(body)
59 return resp, body
60
61 def startup_host(self, hostname):
62 """Startup a host."""
63
64 resp, body = self.get("os-hosts/%s/startup" % str(hostname))
65 body = json.loads(body)
66 return resp, body['host']
67
68 def shutdown_host(self, hostname):
69 """Shutdown a host."""
70
71 resp, body = self.get("os-hosts/%s/shutdown" % str(hostname))
72 body = json.loads(body)
73 return resp, body['host']
74
75 def reboot_host(self, hostname):
76 """reboot a host."""
77
78 resp, body = self.get("os-hosts/%s/reboot" % str(hostname))
79 body = json.loads(body)
80 return resp, body['host']