autoserv revision f36243d8ac8d14e9fee56b304657413c4cd1ea23
1#!/usr/bin/python -u 2# 3# Copyright 2007 Google Inc. Released under the GPL v2 4 5""" 6Run an control file through the server side engine 7""" 8 9__author__ = """\ 10mbligh@google.com (Martin J. Bligh) 11""" 12 13import sys, os, re, server_job 14 15usage = """\ 16usage: autoserv 17 [-m machine,[machine,...]] # list of machines to pass to control file 18 [-c] # control file is a client side control 19 [-r resultsdir] # specify results directory (default '.') 20 [-i] # reinstall machines before running the job 21 [-I] # reinstall machines after running the job 22 [-b] # reboot all specified machines after the job 23 [-l label] # label for the job (arbitrary string) 24 [-u user] # username for the job (email address) 25 <control file> # name of the control file to run 26 [args ...] # args to pass through to the control file 27""" 28 29args = sys.argv[1:] 30 31# We can't use the general getopt methods here, as there will be unknown 32# extra arguments that we pass down into the control file instead. 33# Thus we process the arguments by hand, for which we are duly repentant. 34# Making a single function here just makes it harder to read. Suck it up. 35def parse_opts(flag): 36 if args.count(flag): 37 idx = args.index(flag) 38 args[idx : idx+1] = [] 39 return True 40 else: 41 return False 42 43 44def parse_opts_param(flag, default = None, split = False): 45 if args.count(flag): 46 idx = args.index(flag) 47 ret = args[idx+1] 48 args[idx : idx+2] = [] 49 if split: 50 return ret.split(split) 51 else: 52 return ret 53 else: 54 return default 55 56 57machines = parse_opts_param('-m', None, split = ',') 58results = parse_opts_param('-r', os.path.abspath('.')) 59label = parse_opts_param('-l', '') 60user = parse_opts_param('-u', 'anonymous') 61client = parse_opts('-c') 62reboot = parse_opts('-b') 63install_before = parse_opts('-i') 64install_after = parse_opts('-I') 65 66if len(args) < 1: 67 print usage 68 sys.exit(-1) 69 70job = server_job.server_job(args[0], args[1:], results, label, user, client) 71job.run(machines, reboot, install_before, install_after) 72