3 # Copyright (C) 2014 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 def cmdline (subparsers):
28 p = subparsers.add_parser (
30 help='connect to graphical console of named VM',
34 help='vm (or node:vm) to connect to'
36 p.set_defaults (run=run)
38 def run (c, args, nodes):
39 running, _ = lib.get_all_guests (c, nodes.values ())
41 m = re.match (r'^(.*):(.*)$', args.vm)
44 # We don't actually care about the node, but we check it
45 # is the expected one below.
46 node_name = m.group (1)
51 if vm_name not in running:
52 sys.exit ("error: vm %s not found or not running" % vm_name)
54 dom = running[vm_name]['dom']
55 node = running[vm_name]['node']
57 if node_name and node.name != node_name:
58 sys.exit ("error: vm %s is not running on node %s, did you mean %s:%s ?" %
59 (vm_name, node_name, node.name, vm_name))
61 # Run the virsh console command.
62 subprocess.call ([config.VIRT_VIEWER, "-c", node.uri, vm_name])