blob: 0fadf0dae7593230c6f0a2ca39ec7ad9d7ae9105 [file] [log] [blame]
mbligha6f13082008-06-05 23:53:46 +00001import os, sys, getopt, optparse
mblighb7dcc7f2008-06-02 19:34:25 +00002
mbligha7007722009-01-13 00:37:11 +00003from autotest_lib.client.common_lib import host_protections, utils
jadmanskifbc1f0a2008-07-09 14:12:54 +00004
mblighb7dcc7f2008-06-02 19:34:25 +00005
6class base_autoserv_parser(object):
jadmanski0afbb632008-06-06 21:10:57 +00007 """Custom command-line options parser for autoserv.
mblighb7dcc7f2008-06-02 19:34:25 +00008
jadmanski0afbb632008-06-06 21:10:57 +00009 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()
mblighb7dcc7f2008-06-02 19:34:25 +000019
20
jadmanski0afbb632008-06-06 21:10:57 +000021 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")
mblighb2bea302008-07-24 20:25:57 +000031 self.parser.add_option("-s", action="store_true",
32 dest="server", default=False,
33 help="control file is server side")
jadmanski0afbb632008-06-06 21:10:57 +000034 self.parser.add_option("-r", action="store", type="string",
mbligh80e1eba2008-11-19 00:26:18 +000035 dest="results", default=None,
36 help="specify results directory")
jadmanski0afbb632008-06-06 21:10:57 +000037 self.parser.add_option("-l", action="store", type="string",
38 dest="label", default='',
39 help="label for the job")
40 self.parser.add_option("-u", action="store", type="string",
41 dest="user",
42 default=os.environ.get('USER'),
43 help="username for the job")
44 self.parser.add_option("-P", action="store", type="string",
45 dest="parse_job",
46 default='',
47 help="parse the results of the job")
48 self.parser.add_option("-i", action="store_true",
49 dest="install_before", default=False,
50 help="reinstall machines before running the job")
51 self.parser.add_option("-I", action="store_true",
52 dest="install_after", default=False,
53 help="reinstall machines after running the job")
jadmanski0afbb632008-06-06 21:10:57 +000054 self.parser.add_option("-v", action="store_true",
55 dest="verify", default=False,
56 help="verify the machines only")
57 self.parser.add_option("-R", action="store_true",
58 dest="repair", default=False,
59 help="repair the machines")
showard45ae8192008-11-05 19:32:53 +000060 self.parser.add_option("-C", "--cleanup", action="store_true",
61 default=False,
62 help="cleanup all machines after the job")
jadmanski0afbb632008-06-06 21:10:57 +000063 self.parser.add_option("-n", action="store_true",
64 dest="no_tee", default=False,
65 help="no teeing the status to stdout/err")
mbligh80e1eba2008-11-19 00:26:18 +000066 self.parser.add_option("-N", action="store_true",
67 dest="no_logging", default=False,
68 help="no logging")
jadmanskid5ab8c52008-12-03 16:27:07 +000069 self.parser.add_option("-p", "--write-pidfile", action="store_true",
jadmanski0afbb632008-06-06 21:10:57 +000070 dest="write_pidfile", default=False,
jadmanskid5ab8c52008-12-03 16:27:07 +000071 help="write pidfile (.autoserv_execute)")
jadmanskifbc1f0a2008-07-09 14:12:54 +000072 protection_levels = [host_protections.Protection.get_attr_name(s)
73 for i, s in host_protections.choices]
74 self.parser.add_option("--host-protection", action="store",
75 type="choice", dest="host_protection",
76 default=host_protections.default,
77 choices=protection_levels,
78 help="level of host protection during repair")
jadmanski0afbb632008-06-06 21:10:57 +000079 self.parser.add_option("--ssh-user", action="store",
80 type="string", dest="ssh_user",
81 default="root",
82 help=("specify the user for ssh"
83 "connections"))
84 self.parser.add_option("--ssh-port", action="store",
85 type="int", dest="ssh_port",
86 default=22,
87 help=("specify the port to use for "
88 "ssh connections"))
89 self.parser.add_option("--ssh-pass", action="store",
90 type="string", dest="ssh_pass",
91 default="",
92 help=("specify the password to use "
93 "for ssh connections"))
jadmanskif22fea82008-11-26 20:57:07 +000094 self.parser.add_option("--install-in-tmpdir", action="store_true",
95 dest="install_in_tmpdir", default=False,
96 help=("by default install autotest clients in "
97 "a temporary directory"))
jadmanski0afbb632008-06-06 21:10:57 +000098
99
100 def parse_args(self):
101 (self.options, self.args) = self.parser.parse_args()
mblighb7dcc7f2008-06-02 19:34:25 +0000102
103
mbligha7007722009-01-13 00:37:11 +0000104site_autoserv_parser = utils.import_site_class(
105 __file__, "autotest_lib.server.site_autoserv_parser",
106 "site_autoserv_parser", base_autoserv_parser)
mblighb7dcc7f2008-06-02 19:34:25 +0000107
108class autoserv_parser(site_autoserv_parser):
jadmanski0afbb632008-06-06 21:10:57 +0000109 pass
mblighb7dcc7f2008-06-02 19:34:25 +0000110
111
112# create the one and only one instance of autoserv_parser
113autoserv_parser = autoserv_parser()