Skip to content

Commit 53bbff6

Browse files
author
Dean Troyer
committed
Add console commands
Adds: * console-log * console-url Part of blueprint nova-client Change-Id: Ibea7f96382283770988d05379d41a148f8cd8c4f
1 parent 6b47839 commit 53bbff6

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Copyright 2012-2013 OpenStack Foundation
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+
"""Console action implementations"""
17+
18+
import logging
19+
import sys
20+
21+
from cliff import command
22+
from cliff import show
23+
24+
from openstackclient.common import utils
25+
26+
27+
class ShowConsoleLog(command.Command):
28+
"""Show console-log command"""
29+
30+
api = 'compute'
31+
log = logging.getLogger(__name__ + '.ShowConsoleLog')
32+
33+
def get_parser(self, prog_name):
34+
parser = super(ShowConsoleLog, self).get_parser(prog_name)
35+
parser.add_argument(
36+
'server',
37+
metavar='<server>',
38+
help='Name or ID of server to display console log',
39+
)
40+
parser.add_argument(
41+
'--lines',
42+
metavar='<num-lines>',
43+
type=int,
44+
default=None,
45+
help='Number of lines to display from the end of the log '
46+
'(default=all)',
47+
)
48+
return parser
49+
50+
def take_action(self, parsed_args):
51+
self.log.debug('take_action(%s)' % parsed_args)
52+
compute_client = self.app.client_manager.compute
53+
54+
server = utils.find_resource(
55+
compute_client.servers,
56+
parsed_args.server,
57+
)
58+
# NOTE(dtroyer): get_console_output() appears to shortchange the
59+
# output by one line
60+
data = server.get_console_output(length=parsed_args.lines + 1)
61+
sys.stdout.write(data)
62+
return
63+
64+
65+
class ShowConsoleURL(show.ShowOne):
66+
"""Show console-url command"""
67+
68+
api = 'compute'
69+
log = logging.getLogger(__name__ + '.ShowConsoleURL')
70+
71+
def get_parser(self, prog_name):
72+
parser = super(ShowConsoleURL, self).get_parser(prog_name)
73+
parser.add_argument(
74+
'server',
75+
metavar='<server>',
76+
help='Name or ID of server to display console log',
77+
)
78+
type_group = parser.add_mutually_exclusive_group()
79+
type_group.add_argument(
80+
'--novnc',
81+
dest='url_type',
82+
action='store_const',
83+
const='novnc',
84+
default='novnc',
85+
help='Show noVNC console URL (default)',
86+
)
87+
type_group.add_argument(
88+
'--xvpvnc',
89+
dest='url_type',
90+
action='store_const',
91+
const='xvpvnc',
92+
help='Show xpvnc console URL',
93+
)
94+
type_group.add_argument(
95+
'--spice',
96+
dest='url_type',
97+
action='store_const',
98+
const='spice',
99+
help='Show SPICE console URL',
100+
)
101+
return parser
102+
103+
def take_action(self, parsed_args):
104+
self.log.debug('take_action(%s)' % parsed_args)
105+
compute_client = self.app.client_manager.compute
106+
server = utils.find_resource(
107+
compute_client.servers,
108+
parsed_args.server,
109+
)
110+
111+
print "type: %s" % parsed_args.url_type
112+
if parsed_args.url_type in ['novnc', 'xvpvnc']:
113+
data = server.get_vnc_console(parsed_args.url_type)
114+
if parsed_args.url_type in ['spice']:
115+
data = server.get_spice_console(parsed_args.url_type)
116+
117+
if not data:
118+
return ({}, {})
119+
print "data: %s" % data['console']
120+
121+
info = {}
122+
info.update(data['console'])
123+
return zip(*sorted(info.iteritems()))

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ def read(fname):
193193
'set_compute-service='
194194
'openstackclient.compute.v2.service:SetService',
195195

196+
'show_console-log='
197+
'openstackclient.compute.v2.console:ShowConsoleLog',
198+
'show_console-url='
199+
'openstackclient.compute.v2.console:ShowConsoleURL',
200+
196201
'add_fixed-ip=openstackclient.compute.v2.fixedip:AddFixedIP',
197202
'remove_fixed-ip=openstackclient.compute.v2.fixedip:RemoveFixedIP',
198203

0 commit comments

Comments
 (0)