import argparse import ast import logging import os import shlex import sys class autoserv_parser(object): """Custom command-line options parser for autoserv. We can't use the general getopt methods here, as there will be unknown extra arguments that we pass down into the control file instead. Thus we process the arguments by hand, for which we are duly repentant. Making a single function here just makes it harder to read. Suck it up. """ def __init__(self): self.args = sys.argv[1:] self.parser = argparse.ArgumentParser( usage='%(prog)s [options] [control-file]') self.setup_options() # parse an empty list of arguments in order to set self.options # to default values so that codepaths that assume they are always # reached from an autoserv process (when they actually are not) # will still work self.options = self.parser.parse_args(args=[]) def setup_options(self): """Setup options to call autoserv command. """ self.parser.add_argument('-m', action='store', type=str, dest='machines', help='list of machines') self.parser.add_argument('-M', action='store', type=str, dest='machines_file', help='list of machines from file') self.parser.add_argument('-c', action='store_true', dest='client', default=False, help='control file is client side') self.parser.add_argument('-s', action='store_true', dest='server', default=False, help='control file is server side') self.parser.add_argument('-r', action='store', type=str, dest='results', default=None, help='specify results directory') self.parser.add_argument('-l', action='store', type=str, dest='label', default='', help='label for the job') self.parser.add_argument('-G', action='store', type=str, dest='group_name', default='', help='The host_group_name to store in keyvals') self.parser.add_argument('-u', action='store', type=str, dest='user', default=os.environ.get('USER'), help='username for the job') self.parser.add_argument('-P', action='store', type=str, dest='parse_job', default='', help=('Parse the results of the job using this' ' execution tag. Accessible in control ' 'files as job.tag.')) self.parser.add_argument('--execution-tag', action='store', type=str, dest='execution_tag', default='', help=('Accessible in control files as job.tag;' ' Defaults to the value passed to -P.')) self.parser.add_argument('-i', action='store_true', dest='install_before', default=False, help=('reinstall machines before running the ' 'job')) self.parser.add_argument('-I', action='store_true', dest='install_after', default=False, help=('reinstall machines after running the ' 'job')) self.parser.add_argument('-v', action='store_true', dest='verify', default=False, help='verify the machines only') self.parser.add_argument('-R', action='store_true', dest='repair', default=False, help='repair the machines') self.parser.add_argument('-C', '--cleanup', action='store_true', default=False, help='cleanup all machines after the job') self.parser.add_argument('--provision', action='store_true', default=False, help='Provision the machine.') self.parser.add_argument('--job-labels', action='store', help='Comma seperated job labels.') self.parser.add_argument('-T', '--reset', action='store_true', default=False, help=('Reset (cleanup and verify) all machines' ' after the job')) self.parser.add_argument('-n', action='store_true', dest='no_tee', default=False, help='no teeing the status to stdout/err') self.parser.add_argument('-N', action='store_true', dest='no_logging', default=False, help='no logging') self.parser.add_argument('--verbose', action='store_true', help=('Include DEBUG messages in console ' 'output')) self.parser.add_argument('--no_console_prefix', action='store_true', help=('Disable the logging prefix on console ' 'output')) self.parser.add_argument('-p', '--write-pidfile', action='store_true', dest='write_pidfile', default=False, help=('write pidfile (pidfile name is ' 'determined by --pidfile-label')) self.parser.add_argument('--pidfile-label', action='store', default='autoserv', help=('Determines filename to use as pidfile ' '(if -p is specified). Pidfile will be ' '.