blob: d15b2372c35b6d57a25931ebc7b35d72c4b820d0 [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
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
ivan-zhu8577cb12013-08-20 14:38:36 +080022
23
ivan-zhu00fe64f2013-08-20 19:35:51 +080024class HostsV3ClientJSON(RestClient):
ivan-zhu8577cb12013-08-20 14:38:36 +080025
Matthew Treinish684d8992014-01-30 16:27:40 +000026 def __init__(self, username, password, auth_url, tenant_name=None):
27 super(HostsV3ClientJSON, self).__init__(username, password,
ivan-zhu00fe64f2013-08-20 19:35:51 +080028 auth_url, tenant_name)
Matthew Treinish684d8992014-01-30 16:27:40 +000029 self.service = CONF.compute.catalog_v3_type
ivan-zhu8577cb12013-08-20 14:38:36 +080030
31 def list_hosts(self, params=None):
32 """Lists all hosts."""
33
34 url = 'os-hosts'
35 if params:
36 url += '?%s' % urllib.urlencode(params)
37
38 resp, body = self.get(url)
39 body = json.loads(body)
40 return resp, body['hosts']
41
42 def show_host_detail(self, hostname):
43 """Show detail information for the host."""
44
45 resp, body = self.get("os-hosts/%s" % str(hostname))
46 body = json.loads(body)
47 return resp, body['host']
48
49 def update_host(self, hostname, **kwargs):
50 """Update a host."""
51
52 request_body = {
53 'status': None,
54 'maintenance_mode': None,
55 }
56 request_body.update(**kwargs)
ivan-zhu00fe64f2013-08-20 19:35:51 +080057 request_body = json.dumps({'host': request_body})
ivan-zhu8577cb12013-08-20 14:38:36 +080058
59 resp, body = self.put("os-hosts/%s" % str(hostname), request_body,
60 self.headers)
61 body = json.loads(body)
62 return resp, body
63
64 def startup_host(self, hostname):
65 """Startup a host."""
66
67 resp, body = self.get("os-hosts/%s/startup" % str(hostname))
68 body = json.loads(body)
69 return resp, body['host']
70
71 def shutdown_host(self, hostname):
72 """Shutdown a host."""
73
74 resp, body = self.get("os-hosts/%s/shutdown" % str(hostname))
75 body = json.loads(body)
76 return resp, body['host']
77
78 def reboot_host(self, hostname):
79 """reboot a host."""
80
81 resp, body = self.get("os-hosts/%s/reboot" % str(hostname))
82 body = json.loads(body)
83 return resp, body['host']