#!/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 fnmatch import re import sys import libvirt import lib def cmdline (subparsers): p = subparsers.add_parser ( 'start', help='start virtual machine(s)', ) p.add_argument ( 'vms', nargs='+', help='virtual machine(s) to be started' ) p.set_defaults (run=run) def run (c, args, nodes): _, inactive = lib.get_all_guests (c, nodes.values ()) # User supplied a list of node:VMs. for a in args.vms: m = re.match (r'^(.*):(.*)$', a) if m: node_name = m.group (1) wc = m.group (2) if node_name not in nodes: sys.exit ("error: node %s does not exist" % node_name) node = nodes[node_name] else: wc = a node = lib.pick_any_node_which_is_up (nodes) started = [] for vm_name in inactive: if fnmatch.fnmatch (vm_name, wc): lib.start_guest (c, node, vm_name) started.append (vm_name) if not started: sys.exit ("error: no VMs matched pattern %s" % a) # Make sure we don't start the same VMs again the next # time around the loop: for vm_name in started: del inactive[vm_name]