#!/usr/bin/python # mclu (mini cluster) # Copyright (C) 2014 Red Hat Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import argparse import re import sys import subprocess import lib def cmdline (subparsers): p = subparsers.add_parser ( 'console', help='connect to console of named VM', ) p.add_argument ( 'vm', help='vm (or node:vm) to connect to' ) p.set_defaults (run=run) def run (c, args, nodes): running, _ = lib.get_all_guests (c, nodes.values ()) m = re.match (r'^(.*):(.*)$', args.vm) node_name = None if m: # We don't actually care about the node, but we check it # is the expected one below. node_name = m.group (1) vm_name = m.group (2) else: vm_name = args.vm if vm_name not in running: sys.exit ("error: vm %s not found or not running" % vm_name) dom = running[vm_name]['dom'] node = running[vm_name]['node'] if node_name and node.name != node_name: sys.exit ("error: vm %s is not running on node %s, did you mean %s:%s ?" % (vm_name, node_name, node.name, vm_name)) # Run the virsh console command. subprocess.call (["virsh", "-c", node.uri, "console", vm_name])