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 | |
jadmanski | fbc1f0a | 2008-07-09 14:12:54 +0000 | [diff] [blame] | 3 | from autotest_lib.client.common_lib import host_protections |
| 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() |
| 18 | self.parse_args() |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 19 | |
| 20 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 21 | def setup_options(self): |
| 22 | self.parser.add_option("-m", action="store", type="string", |
| 23 | dest="machines", |
| 24 | help="list of machines") |
| 25 | self.parser.add_option("-M", action="store", type="string", |
| 26 | dest="machines_file", |
| 27 | help="list of machines from file") |
| 28 | self.parser.add_option("-c", action="store_true", |
| 29 | dest="client", default=False, |
| 30 | help="control file is client side") |
mbligh | b2bea30 | 2008-07-24 20:25:57 +0000 | [diff] [blame] | 31 | self.parser.add_option("-s", action="store_true", |
| 32 | dest="server", default=False, |
| 33 | help="control file is server side") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 34 | self.parser.add_option("-r", action="store", type="string", |
mbligh | 7cd30fd | 2008-10-21 16:25:19 +0000 | [diff] [blame] | 35 | dest="results", help="specify results directory") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 36 | self.parser.add_option("-l", action="store", type="string", |
| 37 | dest="label", default='', |
| 38 | help="label for the job") |
| 39 | self.parser.add_option("-u", action="store", type="string", |
| 40 | dest="user", |
| 41 | default=os.environ.get('USER'), |
| 42 | help="username for the job") |
| 43 | self.parser.add_option("-P", action="store", type="string", |
| 44 | dest="parse_job", |
| 45 | default='', |
| 46 | help="parse the results of the job") |
| 47 | self.parser.add_option("-i", action="store_true", |
| 48 | dest="install_before", default=False, |
| 49 | help="reinstall machines before running the job") |
| 50 | self.parser.add_option("-I", action="store_true", |
| 51 | dest="install_after", default=False, |
| 52 | help="reinstall machines after running the job") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 53 | self.parser.add_option("-v", action="store_true", |
| 54 | dest="verify", default=False, |
| 55 | help="verify the machines only") |
| 56 | self.parser.add_option("-R", action="store_true", |
| 57 | dest="repair", default=False, |
| 58 | help="repair the machines") |
showard | 45ae819 | 2008-11-05 19:32:53 +0000 | [diff] [blame^] | 59 | self.parser.add_option("-C", "--cleanup", action="store_true", |
| 60 | default=False, |
| 61 | help="cleanup all machines after the job") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 62 | self.parser.add_option("-n", action="store_true", |
| 63 | dest="no_tee", default=False, |
| 64 | help="no teeing the status to stdout/err") |
| 65 | self.parser.add_option("-p", action="store_true", |
| 66 | dest="write_pidfile", default=False, |
| 67 | help="write pidfile (.autoserv_execute)") |
jadmanski | fbc1f0a | 2008-07-09 14:12:54 +0000 | [diff] [blame] | 68 | protection_levels = [host_protections.Protection.get_attr_name(s) |
| 69 | for i, s in host_protections.choices] |
| 70 | self.parser.add_option("--host-protection", action="store", |
| 71 | type="choice", dest="host_protection", |
| 72 | default=host_protections.default, |
| 73 | choices=protection_levels, |
| 74 | help="level of host protection during repair") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 75 | self.parser.add_option("--ssh-user", action="store", |
| 76 | type="string", dest="ssh_user", |
| 77 | default="root", |
| 78 | help=("specify the user for ssh" |
| 79 | "connections")) |
| 80 | self.parser.add_option("--ssh-port", action="store", |
| 81 | type="int", dest="ssh_port", |
| 82 | default=22, |
| 83 | help=("specify the port to use for " |
| 84 | "ssh connections")) |
| 85 | self.parser.add_option("--ssh-pass", action="store", |
| 86 | type="string", dest="ssh_pass", |
| 87 | default="", |
| 88 | help=("specify the password to use " |
| 89 | "for ssh connections")) |
| 90 | |
| 91 | |
| 92 | def parse_args(self): |
| 93 | (self.options, self.args) = self.parser.parse_args() |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 94 | |
| 95 | |
| 96 | |
| 97 | try: |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 98 | from autotest_lib.server.site_autoserv_parser \ |
| 99 | import site_autoserv_parser |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 100 | except ImportError: |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 101 | class site_autoserv_parser(base_autoserv_parser): |
| 102 | pass |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 103 | |
| 104 | |
| 105 | class autoserv_parser(site_autoserv_parser): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 106 | pass |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 107 | |
| 108 | |
| 109 | # create the one and only one instance of autoserv_parser |
| 110 | autoserv_parser = autoserv_parser() |