blob: 30a3f7bfe2c684cd4ac6c03f25f62d6313335c42 [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
Mate Lakat99ee9142012-09-14 12:34:46 +010017import json
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080018import urllib
Mate Lakat99ee9142012-09-14 12:34:46 +010019
Matthew Treinisha83a16e2012-12-07 13:44:02 -050020from tempest.common.rest_client import RestClient
21
Mate Lakat99ee9142012-09-14 12:34:46 +010022
23class HostsClientJSON(RestClient):
24
25 def __init__(self, config, username, password, auth_url, tenant_name=None):
26 super(HostsClientJSON, self).__init__(config, username, password,
27 auth_url, tenant_name)
28 self.service = self.config.compute.catalog_type
29
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080030 def list_hosts(self, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -050031 """Lists all hosts."""
Mate Lakat99ee9142012-09-14 12:34:46 +010032
33 url = 'os-hosts'
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080034 if params:
35 url += '?%s' % urllib.urlencode(params)
36
Mate Lakat99ee9142012-09-14 12:34:46 +010037 resp, body = self.get(url)
38 body = json.loads(body)
39 return resp, body['hosts']
Zhu Zhuff150052013-09-17 17:48:39 +080040
41 def show_host_detail(self, hostname):
42 """Show detail information for the host."""
43
44 resp, body = self.get("os-hosts/%s" % str(hostname))
45 body = json.loads(body)
46 return resp, body['host']