report any expired sites & nodes
[monitor.git] / automate / fetch.py
1 #!/usr/bin/python
2
3 import csv
4 import sys
5 import os
6 from glob import glob
7
8 import vxargs
9 from monitor import parser as parsermodule
10 from monitor import common
11 from automate import *
12
13 def build_vx_args(shell_cmd):
14         ssh_options="-q -o UserKnownHostsFile=junkssh -o StrictHostKeyChecking=no"
15         cmd="""ssh %s root@{} """  % ssh_options
16         args = cmd.split()
17         args.append(shell_cmd)
18         return args
19
20 def vx_start(filelist,outdir,cmd, timeout=0):
21         args = build_vx_args(cmd)
22         vxargs.start(None, 20, filelist, outdir, False, args, timeout)
23
24 if __name__ == "__main__":
25
26         parser = parsermodule.getParser(['nodesets'])
27         parser.set_defaults(outdir=None,
28                                                 timeout=0,
29                                                 simple=False,
30                                                 run=False,
31                                                 cmdfile=None,)
32
33         parser.add_option("", "--timeout", dest="timeout", metavar="seconds",
34                                                 help="Number of seconds to wait before timing out on host.")
35         parser.add_option("", "--outdir", dest="outdir", metavar="dirname",
36                                                 help="Name of directory to place output")
37         parser.add_option("", "--cmd", dest="cmdfile", metavar="filename",
38                                                 help="Name of file that contains a unix-to-csv command " + \
39                                                          "to run on the hosts.")
40
41         config = parsermodule.parse_args(parser)
42
43         if config.outdir == None: 
44                 outdir="checkhosts"
45         else: 
46                 outdir=config.outdir
47
48         if not os.path.exists(outdir):
49                 os.system('mkdir -p %s' % outdir)
50
51         #if config.site is not None or \
52         #   config.nodeselect is not None or \
53         #   config.nodegroup is not None:
54         #       print "TODO: implement support for nodeselect and site queries."
55         #       print "%s %s %s" % (config.site, config.nodeselect, config.nodegroup)
56         #       sys.exit(1)
57
58         nodelist = common.get_nodeset(config)
59
60         if len(nodelist) > 0:
61                 filelist = [ (x, '') for x in nodelist ]
62         elif os.path.exists(str(config.nodelist)) and os.path.isfile(config.nodelist):
63                 filelist = vxargs.getListFromFile(open(config.nodelist,'r'))
64         elif os.path.exists(str(config.nodelist)) and os.path.isdir(config.nodelist):
65                 filelist = get_hostlist_from_dir(config.nodelist)
66         elif config.node is not None:
67                 filelist = [(config.node, '')]
68         else:
69                 # probably no such file.
70                 raise Exception("No such file %s" % config.nodelist)
71
72         if config.cmdfile == None:
73                 f = open("command.txt",'r')
74                 cmd = f.read()
75         else:
76                 f = open(config.cmdfile,'r')
77                 cmd = f.read()
78
79         print filelist
80
81         vx_start(filelist, outdir, cmd, int(config.timeout))