Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 1 | # 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 Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 17 | import json |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 18 | import urllib |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 19 | |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 20 | from tempest.common.rest_client import RestClient |
| 21 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 22 | |
| 23 | class 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 Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 30 | def list_hosts(self, params=None): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 31 | """Lists all hosts.""" |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 32 | |
| 33 | url = 'os-hosts' |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 34 | if params: |
| 35 | url += '?%s' % urllib.urlencode(params) |
| 36 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 37 | resp, body = self.get(url) |
| 38 | body = json.loads(body) |
| 39 | return resp, body['hosts'] |
Zhu Zhu | ff15005 | 2013-09-17 17:48:39 +0800 | [diff] [blame^] | 40 | |
| 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'] |