Skip to content

Commit ebfad58

Browse files
committed
Added compute hypervisor support.
Change-Id: Ib8109550b06d152773394a1d15f6202b9f9b029c
1 parent 331d64a commit ebfad58

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright 2013 OpenStack, LLC.
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+
#
15+
16+
"""Hypervisor action implementations"""
17+
18+
import logging
19+
20+
from cliff import lister
21+
from cliff import show
22+
23+
from openstackclient.common import utils
24+
25+
26+
class ListHypervisor(lister.Lister):
27+
"""List hypervisor command"""
28+
29+
api = "compute"
30+
log = logging.getLogger(__name__ + ".ListHypervisor")
31+
32+
def get_parser(self, prog_name):
33+
parser = super(ListHypervisor, self).get_parser(prog_name)
34+
parser.add_argument(
35+
"--matching",
36+
metavar="<hostname>",
37+
help="List hypervisors with hostnames matching the given"
38+
" substring")
39+
return parser
40+
41+
def take_action(self, parsed_args):
42+
self.log.debug("take_action(%s)" % parsed_args)
43+
compute_client = self.app.client_manager.compute
44+
columns = (
45+
"ID",
46+
"Hypervisor Hostname"
47+
)
48+
49+
if parsed_args.matching:
50+
data = compute_client.hypervisors.search(parsed_args.matching)
51+
else:
52+
data = compute_client.hypervisors.list()
53+
54+
return (columns,
55+
(utils.get_item_properties(
56+
s, columns,
57+
) for s in data))
58+
59+
60+
class ShowHypervisor(show.ShowOne):
61+
"""Show hypervisor command"""
62+
63+
api = "compute"
64+
log = logging.getLogger(__name__ + ".ShowHypervisor")
65+
66+
def get_parser(self, prog_name):
67+
parser = super(ShowHypervisor, self).get_parser(prog_name)
68+
parser.add_argument(
69+
"id",
70+
metavar="<id>",
71+
help="ID of the hypervisor to display")
72+
return parser
73+
74+
def take_action(self, parsed_args):
75+
self.log.debug("take_action(%s)" % parsed_args)
76+
compute_client = self.app.client_manager.compute
77+
hypervisor = utils.find_resource(compute_client.hypervisors,
78+
parsed_args.id)._info.copy()
79+
80+
hypervisor["service_id"] = hypervisor["service"]["id"]
81+
hypervisor["service_host"] = hypervisor["service"]["host"]
82+
del hypervisor["service"]
83+
84+
return zip(*sorted(hypervisor.iteritems()))

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def read(fname):
148148
'list_agent=openstackclient.compute.v2.agent:ListAgent',
149149
'list_flavor=openstackclient.compute.v2.flavor:ListFlavor',
150150
'list_host=openstackclient.compute.v2.host:ListHost',
151+
'list_hypervisor=' +
152+
'openstackclient.compute.v2.hypervisor:ListHypervisor',
151153
'list_server=openstackclient.compute.v2.server:ListServer',
152154
'list_compute-service=' +
153155
'openstackclient.compute.v2.service:ListService',
@@ -160,6 +162,8 @@ def read(fname):
160162
'openstackclient.compute.v2.service:SetService',
161163
'show_flavor=openstackclient.compute.v2.flavor:ShowFlavor',
162164
'show_host=openstackclient.compute.v2.host:ShowHost',
165+
'show_hypervisor=' +
166+
'openstackclient.compute.v2.hypervisor:ShowHypervisor',
163167
'show_server=openstackclient.compute.v2.server:ShowServer',
164168
'suspend_server=openstackclient.compute.v2.server:SuspendServer',
165169
'unpause_server=openstackclient.compute.v2.server:UnpauseServer',

0 commit comments

Comments
 (0)