mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 1 | __author__ = "raphtee@google.com (Travis Miller)" |
| 2 | |
| 3 | |
mbligh | a6f1308 | 2008-06-05 23:53:46 +0000 | [diff] [blame] | 4 | import os, sys, getopt, optparse |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 5 | |
| 6 | |
| 7 | class base_autoserv_parser(object): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 8 | """Custom command-line options parser for autoserv. |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 9 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 10 | We can't use the general getopt methods here, as there will be unknown |
| 11 | extra arguments that we pass down into the control file instead. |
| 12 | Thus we process the arguments by hand, for which we are duly repentant. |
| 13 | Making a single function here just makes it harder to read. Suck it up. |
| 14 | """ |
| 15 | def __init__(self): |
| 16 | self.args = sys.argv[1:] |
| 17 | self.parser = optparse.OptionParser() |
| 18 | self.setup_options() |
| 19 | self.parse_args() |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 20 | |
| 21 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 22 | def setup_options(self): |
| 23 | self.parser.add_option("-m", action="store", type="string", |
| 24 | dest="machines", |
| 25 | help="list of machines") |
| 26 | self.parser.add_option("-M", action="store", type="string", |
| 27 | dest="machines_file", |
| 28 | help="list of machines from file") |
| 29 | self.parser.add_option("-c", action="store_true", |
| 30 | dest="client", default=False, |
| 31 | help="control file is client side") |
| 32 | self.parser.add_option("-r", action="store", type="string", |
| 33 | dest="results", default='.', |
| 34 | help="specify results directory") |
| 35 | self.parser.add_option("-l", action="store", type="string", |
| 36 | dest="label", default='', |
| 37 | help="label for the job") |
| 38 | self.parser.add_option("-u", action="store", type="string", |
| 39 | dest="user", |
| 40 | default=os.environ.get('USER'), |
| 41 | help="username for the job") |
| 42 | self.parser.add_option("-P", action="store", type="string", |
| 43 | dest="parse_job", |
| 44 | default='', |
| 45 | help="parse the results of the job") |
| 46 | self.parser.add_option("-i", action="store_true", |
| 47 | dest="install_before", default=False, |
| 48 | help="reinstall machines before running the job") |
| 49 | self.parser.add_option("-I", action="store_true", |
| 50 | dest="install_after", default=False, |
| 51 | help="reinstall machines after running the job") |
| 52 | self.parser.add_option("-b", action="store_true", |
| 53 | dest="reboot", default=False, |
| 54 | help="reboot all machines after job") |
| 55 | self.parser.add_option("-v", action="store_true", |
| 56 | dest="verify", default=False, |
| 57 | help="verify the machines only") |
| 58 | self.parser.add_option("-R", action="store_true", |
| 59 | dest="repair", default=False, |
| 60 | help="repair the machines") |
| 61 | self.parser.add_option("-n", action="store_true", |
| 62 | dest="no_tee", default=False, |
| 63 | help="no teeing the status to stdout/err") |
| 64 | self.parser.add_option("-p", action="store_true", |
| 65 | dest="write_pidfile", default=False, |
| 66 | help="write pidfile (.autoserv_execute)") |
| 67 | self.parser.add_option("--ssh-user", action="store", |
| 68 | type="string", dest="ssh_user", |
| 69 | default="root", |
| 70 | help=("specify the user for ssh" |
| 71 | "connections")) |
| 72 | self.parser.add_option("--ssh-port", action="store", |
| 73 | type="int", dest="ssh_port", |
| 74 | default=22, |
| 75 | help=("specify the port to use for " |
| 76 | "ssh connections")) |
| 77 | self.parser.add_option("--ssh-pass", action="store", |
| 78 | type="string", dest="ssh_pass", |
| 79 | default="", |
| 80 | help=("specify the password to use " |
| 81 | "for ssh connections")) |
| 82 | |
| 83 | |
| 84 | def parse_args(self): |
| 85 | (self.options, self.args) = self.parser.parse_args() |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 86 | |
| 87 | |
| 88 | |
| 89 | try: |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 90 | from autotest_lib.server.site_autoserv_parser \ |
| 91 | import site_autoserv_parser |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 92 | except ImportError: |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 93 | class site_autoserv_parser(base_autoserv_parser): |
| 94 | pass |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 95 | |
| 96 | |
| 97 | class autoserv_parser(site_autoserv_parser): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 98 | pass |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 99 | |
| 100 | |
| 101 | # create the one and only one instance of autoserv_parser |
| 102 | autoserv_parser = autoserv_parser() |