blob: b32e8892301e7a3b00ffbd293676ba804cf07383 [file] [log] [blame]
mblighb7dcc7f2008-06-02 19:34:25 +00001__author__ = "raphtee@google.com (Travis Miller)"
2
3
mbligha6f13082008-06-05 23:53:46 +00004import os, sys, getopt, optparse
mblighb7dcc7f2008-06-02 19:34:25 +00005
6
7class base_autoserv_parser(object):
jadmanski0afbb632008-06-06 21:10:57 +00008 """Custom command-line options parser for autoserv.
mblighb7dcc7f2008-06-02 19:34:25 +00009
jadmanski0afbb632008-06-06 21:10:57 +000010 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()
mblighb7dcc7f2008-06-02 19:34:25 +000020
21
jadmanski0afbb632008-06-06 21:10:57 +000022 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()
mblighb7dcc7f2008-06-02 19:34:25 +000086
87
88
89try:
jadmanski0afbb632008-06-06 21:10:57 +000090 from autotest_lib.server.site_autoserv_parser \
91 import site_autoserv_parser
mblighb7dcc7f2008-06-02 19:34:25 +000092except ImportError:
jadmanski0afbb632008-06-06 21:10:57 +000093 class site_autoserv_parser(base_autoserv_parser):
94 pass
mblighb7dcc7f2008-06-02 19:34:25 +000095
96
97class autoserv_parser(site_autoserv_parser):
jadmanski0afbb632008-06-06 21:10:57 +000098 pass
mblighb7dcc7f2008-06-02 19:34:25 +000099
100
101# create the one and only one instance of autoserv_parser
102autoserv_parser = autoserv_parser()