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.
26 def cmdline (subparsers):
27 p = subparsers.add_parser (
29 help='connect to console of named VM',
33 help='vm (or node:vm) to connect to'
35 p.set_defaults (run=run)
38 running, _ = lib.get_all_guests (c)
40 m = re.match (r'^(.*):(.*)$', args.vm)
42 # We don't actually care about the node, but we check it
43 # is the expected one below.
44 node_name_check = m.group (1)
47 node_name_check = None
50 if vm_name not in running:
51 sys.exit ("error: vm %s not found or not running" % vm_name)
53 vm = running[vm_name]['vm']
54 node_name = running[vm_name]['node']
56 if node_name_check and node_name != node_name_check:
57 sys.exit ("error: vm %s is not running on node %s, did you mean %s:%s ?" %
58 (vm_name, node_name_check, node_name, vm_name))
60 # Run the virsh console command.
61 subprocess.call (["virsh",
62 "-c", lib.uri_of_node (node_name),