5 api = plc.PLC(auth.auth, auth.plc)
10 from datetime import datetime, timedelta
16 from nodecommon import *
18 def get_filefromglob(d, str):
21 # TODO: This is aweful.
23 archive = database.SPickle(path)
24 glob_str = "%s*.%s.pkl" % (d.strftime("%Y-%m-%d"), str)
27 file = glob.glob(glob_str)[0]
28 #print "loading %s" % file
31 #fb = archive.load(file[:-4])
34 def fb_print_nodeinfo(fbnode, verbose, date=None):
35 if verbose: print " state | ssh | pcu | bootcd | category | kernel"
36 if 'checked' in fbnode:
37 print "%11.11s " % diff_time(fbnode['checked']),
40 else: print "Unknown",
43 fbnode['bootcd'] = fbnode['bootcd'].split()[-1]
45 fbnode['bootcd'] = "unknown"
46 fbnode['state'] = color_boot_state(get_current_state(fbnode))
47 if len(fbnode['kernel'].split()) >= 3:
48 fbnode['kernel'] = fbnode['kernel'].split()[2]
49 print " %(state)5s | %(ssh)5.5s | %(pcu)5.5s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode
51 def pcu_print_info(pcuinfo, hostname):
53 if 'checked' in pcuinfo:
54 print "%11.11s " % diff_time(pcuinfo['checked'])
58 print "\t user | password | port | hostname "
59 print "\t %17s | %17s | %4s | %30s | %s" % \
60 (pcuinfo['username'], pcuinfo['password'],
61 pcuinfo[hostname], reboot.pcu_name(pcuinfo), pcuinfo['model'])
63 if 'portstatus' in pcuinfo and pcuinfo['portstatus'] != {}:
64 if pcuinfo['portstatus']['22'] == "open":
65 print "\t ssh -o PasswordAuthentication=yes -o PubkeyAuthentication=no %s@%s" % (pcuinfo['username'], reboot.pcu_name(pcuinfo))
66 if pcuinfo['portstatus']['23'] == "open":
67 print "\t telnet %s" % (reboot.pcu_name(pcuinfo))
68 if pcuinfo['portstatus']['80'] == "open" or \
69 pcuinfo['portstatus']['443'] == "open":
70 print "\t http://%s" % (reboot.pcu_name(pcuinfo))
71 if pcuinfo['portstatus']['443'] == "open":
72 print "\t racadm.py -r %s -u %s -p '%s'" % (pcuinfo['ip'], pcuinfo['username'], pcuinfo['password'])
73 print "\t cmdhttps/locfg.pl -s %s -f iloxml/Reset_Server.xml -u %s -p '%s' | grep MESSAGE" % \
74 (reboot.pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password'])
77 from config import config
78 from optparse import OptionParser
80 parser = OptionParser()
81 parser.set_defaults(node=None, fields='state', fromtime=None)
82 parser.add_option("", "--node", dest="node", metavar="nodename.edu",
83 help="A single node name to add to the nodegroup")
84 parser.add_option("", "--fields", dest="fields", metavar="key",
85 help="Which record field to extract from all files.")
86 parser.add_option("", "--fromtime", dest="fromtime", metavar="YYYY-MM-DD",
87 help="Specify a starting date from which to begin the query.")
88 config = config(parser)
92 archive = database.SPickle(path)
95 begin = config.fromtime
99 if config.node is None and len(config.args) > 0:
100 config.node = config.args[0]
101 elif config.node is None:
102 print "Add a hostname to arguments"
106 d = datetime_fromstr(begin)
107 tdelta = timedelta(1)
111 file = get_filefromglob(d, "production.findbad")
112 #file = "%s.production.findbad" % d.strftime("%Y-%m-%d")
115 fb = archive.load(file)
116 if config.node in fb['nodes']:
117 fb_nodeinfo = fb['nodes'][config.node]['values']
118 fb_print_nodeinfo(fb_nodeinfo, verbose, d.strftime("%Y-%m-%d"))
122 except KeyboardInterrupt:
125 #import traceback; print traceback.print_exc()
126 print d.strftime("%Y-%m-%d"), "No record"
129 if d > datetime.now(): break
131 if __name__ == "__main__":