#!/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 config import lib def cmdline (subparsers): p = subparsers.add_parser ( 'viewer', help='connect to graphical 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): running, _ = lib.get_all_guests (c) m = re.match (r'^(.*):(.*)$', args.vm) if m: # We don't actually care about the node, but we check it # is the expected one below. node_name_check = m.group (1) vm_name = m.group (2) else: node_name_check = None vm_name = args.vm if vm_name not in running: sys.exit ("error: vm %s not found or not running" % vm_name) vm = running[vm_name]['vm'] node_name = running[vm_name]['node'] if node_name_check and node_name != node_name_check: sys.exit ("error: vm %s is not running on node %s, did you mean %s:%s ?" % (vm_name, node_name_check, node_name, vm_name)) # Run the virsh console command. subprocess.call ([config.VIRT_VIEWER, "-c", lib.uri_of_node (node_name), vm_name])