mbligh | a6f1308 | 2008-06-05 23:53:46 +0000 | [diff] [blame] | 1 | import os, sys, getopt, optparse |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 2 | |
mbligh | a700772 | 2009-01-13 00:37:11 +0000 | [diff] [blame] | 3 | from autotest_lib.client.common_lib import host_protections, utils |
jadmanski | fbc1f0a | 2008-07-09 14:12:54 +0000 | [diff] [blame] | 4 | |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 5 | |
| 6 | class base_autoserv_parser(object): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 7 | """Custom command-line options parser for autoserv. |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 8 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 9 | We can't use the general getopt methods here, as there will be unknown |
| 10 | extra arguments that we pass down into the control file instead. |
| 11 | Thus we process the arguments by hand, for which we are duly repentant. |
| 12 | Making a single function here just makes it harder to read. Suck it up. |
| 13 | """ |
| 14 | def __init__(self): |
| 15 | self.args = sys.argv[1:] |
| 16 | self.parser = optparse.OptionParser() |
| 17 | self.setup_options() |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 18 | |
mbligh | f82a182 | 2009-02-26 00:47:14 +0000 | [diff] [blame^] | 19 | # parse an empty list of arguments in order to set self.options |
| 20 | # to default values so that codepaths that assume they are always |
| 21 | # reached from an autoserv process (when they actually are not) |
| 22 | # will still work |
| 23 | self.options, self.args = self.parser.parse_args(args=[]) |
| 24 | |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 25 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 26 | def setup_options(self): |
| 27 | self.parser.add_option("-m", action="store", type="string", |
| 28 | dest="machines", |
| 29 | help="list of machines") |
| 30 | self.parser.add_option("-M", action="store", type="string", |
| 31 | dest="machines_file", |
| 32 | help="list of machines from file") |
| 33 | self.parser.add_option("-c", action="store_true", |
| 34 | dest="client", default=False, |
| 35 | help="control file is client side") |
mbligh | b2bea30 | 2008-07-24 20:25:57 +0000 | [diff] [blame] | 36 | self.parser.add_option("-s", action="store_true", |
| 37 | dest="server", default=False, |
| 38 | help="control file is server side") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 39 | self.parser.add_option("-r", action="store", type="string", |
mbligh | 80e1eba | 2008-11-19 00:26:18 +0000 | [diff] [blame] | 40 | dest="results", default=None, |
| 41 | help="specify results directory") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 42 | self.parser.add_option("-l", action="store", type="string", |
| 43 | dest="label", default='', |
| 44 | help="label for the job") |
| 45 | self.parser.add_option("-u", action="store", type="string", |
| 46 | dest="user", |
| 47 | default=os.environ.get('USER'), |
| 48 | help="username for the job") |
| 49 | self.parser.add_option("-P", action="store", type="string", |
| 50 | dest="parse_job", |
| 51 | default='', |
| 52 | help="parse the results of the job") |
| 53 | self.parser.add_option("-i", action="store_true", |
| 54 | dest="install_before", default=False, |
| 55 | help="reinstall machines before running the job") |
| 56 | self.parser.add_option("-I", action="store_true", |
| 57 | dest="install_after", default=False, |
| 58 | help="reinstall machines after running the job") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 59 | self.parser.add_option("-v", action="store_true", |
| 60 | dest="verify", default=False, |
| 61 | help="verify the machines only") |
| 62 | self.parser.add_option("-R", action="store_true", |
| 63 | dest="repair", default=False, |
| 64 | help="repair the machines") |
showard | 45ae819 | 2008-11-05 19:32:53 +0000 | [diff] [blame] | 65 | self.parser.add_option("-C", "--cleanup", action="store_true", |
| 66 | default=False, |
| 67 | help="cleanup all machines after the job") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 68 | self.parser.add_option("-n", action="store_true", |
| 69 | dest="no_tee", default=False, |
| 70 | help="no teeing the status to stdout/err") |
mbligh | 80e1eba | 2008-11-19 00:26:18 +0000 | [diff] [blame] | 71 | self.parser.add_option("-N", action="store_true", |
| 72 | dest="no_logging", default=False, |
| 73 | help="no logging") |
jadmanski | d5ab8c5 | 2008-12-03 16:27:07 +0000 | [diff] [blame] | 74 | self.parser.add_option("-p", "--write-pidfile", action="store_true", |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 75 | dest="write_pidfile", default=False, |
jadmanski | d5ab8c5 | 2008-12-03 16:27:07 +0000 | [diff] [blame] | 76 | help="write pidfile (.autoserv_execute)") |
jadmanski | fbc1f0a | 2008-07-09 14:12:54 +0000 | [diff] [blame] | 77 | protection_levels = [host_protections.Protection.get_attr_name(s) |
| 78 | for i, s in host_protections.choices] |
| 79 | self.parser.add_option("--host-protection", action="store", |
| 80 | type="choice", dest="host_protection", |
| 81 | default=host_protections.default, |
| 82 | choices=protection_levels, |
| 83 | help="level of host protection during repair") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 84 | self.parser.add_option("--ssh-user", action="store", |
| 85 | type="string", dest="ssh_user", |
| 86 | default="root", |
| 87 | help=("specify the user for ssh" |
| 88 | "connections")) |
| 89 | self.parser.add_option("--ssh-port", action="store", |
| 90 | type="int", dest="ssh_port", |
| 91 | default=22, |
| 92 | help=("specify the port to use for " |
| 93 | "ssh connections")) |
| 94 | self.parser.add_option("--ssh-pass", action="store", |
| 95 | type="string", dest="ssh_pass", |
| 96 | default="", |
| 97 | help=("specify the password to use " |
| 98 | "for ssh connections")) |
jadmanski | f22fea8 | 2008-11-26 20:57:07 +0000 | [diff] [blame] | 99 | self.parser.add_option("--install-in-tmpdir", action="store_true", |
| 100 | dest="install_in_tmpdir", default=False, |
| 101 | help=("by default install autotest clients in " |
| 102 | "a temporary directory")) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 103 | |
| 104 | |
| 105 | def parse_args(self): |
mbligh | f82a182 | 2009-02-26 00:47:14 +0000 | [diff] [blame^] | 106 | self.options, self.args = self.parser.parse_args() |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 107 | |
| 108 | |
mbligh | a700772 | 2009-01-13 00:37:11 +0000 | [diff] [blame] | 109 | site_autoserv_parser = utils.import_site_class( |
| 110 | __file__, "autotest_lib.server.site_autoserv_parser", |
| 111 | "site_autoserv_parser", base_autoserv_parser) |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 112 | |
| 113 | class autoserv_parser(site_autoserv_parser): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 114 | pass |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 115 | |
| 116 | |
| 117 | # create the one and only one instance of autoserv_parser |
| 118 | autoserv_parser = autoserv_parser() |