+ executable, exec_args, command, filelist)
+
+
+def ParseOptions():
+ """Parses the command line options.
+
+ In case of command line errors, it will show the usage and exit the
+ program.
+
+ @return: the options in a tuple
+
+ """
+ # resolve because original used -h for hostfile, which conflicts
+ # with -h for help
+ parser = optparse.OptionParser(usage="\n%s" % USAGE,
+ conflict_handler="resolve")
+
+ parser.add_option("-l", dest="logdir", default=None,
+ help="directory to write logfiles to")
+ parser.add_option("-x", dest="executable", default=None,
+ help="executable to run on remote host(s)",)
+ parser.add_option("-f", dest="hostfile", default=None,
+ help="hostlist file (one host per line)")
+ parser.add_option("-h", dest="hostlist", default=None, metavar="HOSTS",
+ help="comma-separated list of hosts or single hostname",)
+ parser.add_option("-a", dest="auxfiles", action="append", default=[],
+ help="optional auxiliary file to upload"
+ " (can be given multiple times)",
+ metavar="FILE")
+ parser.add_option("-c", dest="command", default=None,
+ help="shell command to run on remote host(s)")
+ parser.add_option("-b", dest="batch_size", default=15, type="int",
+ help="batch-size, how many hosts to process"
+ " in parallel [15]")
+ parser.add_option("-u", dest="username", default="root",
+ help="username used to connect [root]")
+ parser.add_option("-p", dest="password", default=None,
+ help="password used to authenticate (when not"
+ " using an agent)")
+ parser.add_option("-A", dest="use_agent", default=False, action="store_true",
+ help="instead of password, use keys from an SSH agent")
+ parser.add_option("--args", dest="exec_args", default=None,
+ help="Arguments to be passed to executable (-x)")
+
+ opts, args = parser.parse_args()
+
+ if opts.executable and opts.command:
+ parser.error("Options -x and -c conflict with each other")
+ if not (opts.executable or opts.command):
+ parser.error("One of -x and -c must be given")
+ if opts.command and opts.exec_args:
+ parser.error("Can't specify arguments when using custom command")
+ if not opts.logdir:
+ parser.error("Option -l is required")
+ if opts.hostfile and opts.hostlist:
+ parser.error("Options -f and -h conflict with each other")
+ if not (opts.hostfile or opts.hostlist):
+ parser.error("One of -f or -h must be given")
+ if args:
+ parser.error("This program doesn't take any arguments, passed in: %s" %
+ ", ".join(args))
+
+ return (opts.logdir, opts.executable, opts.exec_args,
+ opts.hostfile, opts.hostlist,
+ opts.command, opts.use_agent, opts.auxfiles, opts.username,
+ opts.password, opts.batch_size)