7 from optparse import OptionParser
10 def parse_bool(option, opt_str, value, parser):
11 if opt_str in ["--debug"]:
12 parser.values.debug = int(int(value))
13 elif opt_str in ["--mail"]:
14 parser.values.mail = int(int(value))
15 elif opt_str in ["--bcc"]:
16 parser.values.bcc = int(int(value))
17 elif opt_str in ["--policysavedb"]:
18 parser.values.policysavedb = int(int(value))
19 elif opt_str in ["--squeeze"]:
20 parser.values.squeeze = int(int(value))
24 def parseSetDefaults(parser=None):
26 parser = OptionParser()
28 parser.set_defaults(debug = config.debug,
33 squeeze = config.squeeze,
34 policysavedb = config.policysavedb)
36 parser.add_option("", "--debug", dest="debug",
37 help="Enable debugging",
42 parser.add_option("", "--mail", dest="mail",
43 help="Enable sending email",
48 parser.add_option("", "--bcc", dest="bcc",
49 help="Include BCC to user",
54 parser.add_option("", "--squeeze", dest="squeeze",
55 help="Squeeze sites or not",
60 parser.add_option("", "--policysavedb", dest="policysavedb",
61 help="Save the policy event database after a run",
66 parser.add_option("", "--run", dest="run",
68 help="Perform monitor or print configs")
69 parser.add_option("", "--email", dest="email",
70 help="Specify an email address to use for mail when "+\
71 "debug is enabled or for bcc when it is not")
74 def parseSetCacheSet(parser=None):
76 parser = OptionParser()
78 parser.set_defaults(cachecalls=True, cachetime=60)
79 parser.add_option("", "--nocache", dest="cachecalls", action="store_false",
80 help="When using PLCCache objects, temporarily disable the use of caching. i.e. refresh")
81 parser.add_option("", "--cachetime", dest="cachetime",
82 help="How long to preserve a cached value. Minutes")
85 def parseSetNodeSets(parser=None):
87 parser = OptionParser()
89 parser.set_defaults(node=None, site=None, sitelist=None, nodelist=None, nodeselect=None, nodegroup=None)
90 parser.add_option("", "--node", dest="node", metavar="hostname",
91 help="Provide a single node to operate on")
92 parser.add_option("", "--site", dest="site", metavar="site name",
93 help="Specify a single site to operate on")
94 parser.add_option("", "--sitelist", dest="sitelist", metavar="site name",
95 help="Specify a list of sites, separated by ','")
96 parser.add_option("", "--nodegroup", dest="nodegroup", metavar="GroupName",
97 help="Provide the nodegroup for the list of nodes.")
98 parser.add_option("", "--nodelist", dest="nodelist", metavar="FILE",
99 help="Provide the input file for the list of objects")
100 parser.add_option("", "--nodeselect", dest="nodeselect", metavar="query string",
101 help="Provide a selection string to return a node list.")
105 def getParser(parsesets=[], parser=None):
111 if 'cacheset' in parsesets:
112 p = parseSetCacheSet(p)
114 if 'nodesets' in parsesets:
115 p = parseSetNodeSets(p)
116 if 'defaults' in parsesets:
117 p = parseSetDefaults(p)
121 def parse_args(parser):
123 (options, args) = parser.parse_args()
125 o.__dict__.update(options.__dict__)
126 o.__dict__['args'] = args
128 config.updatemodule(config, o)
131 def print_values(parser):
133 for key in parser.__dict__.keys():
134 if key not in exclude:
135 print "%20s == %s" % (key, parser.__dict__[key])