5 api = plc.PLC(auth.auth, auth.plc)
8 fb = soltesz.dbLoad("findbad")
9 act_all = soltesz.dbLoad("act_all")
15 from config import config
16 from optparse import OptionParser
18 parser = OptionParser()
19 parser.set_defaults(node=None)
20 parser.add_option("", "--node", dest="node", metavar="nodename.edu",
21 help="A single node name to add to the nodegroup")
22 config = config(parser)
25 def diff_time(timestamp):
27 diff = now - timestamp
28 # return the number of seconds as a difference from current time.
30 if diff < 60: # sec in min.
32 t_str = "%s sec ago" % t
33 elif diff < 60*60: # sec in hour
35 t_str = "%s min ago" % int(t)
36 elif diff < 60*60*24: # sec in day
38 t_str = "%s hours ago" % int(t)
39 elif diff < 60*60*24*7: # sec in week
40 t = diff // (60*60*24)
41 t_str = "%s days ago" % int(t)
42 elif diff < 60*60*24*30: # approx sec in month
43 t = diff // (60*60*24*7)
44 t_str = "%s weeks ago" % int(t)
45 elif diff > 60*60*24*30: # approx sec in month
46 t = diff // (60*60*24*7*30)
47 t_str = "%s months ago" % int(t)
50 def plc_print_nodeinfo(plcnode):
51 url = "https://www.planet-lab.org/db/nodes/index.php?nodepattern="
52 plcnode['url'] = url + plcnode['hostname']
54 print "%(hostname)s %(url)s" % plcnode
55 print " Checked: %s" % time.ctime()
57 print "\t boot_state | created | updated | last_contact"
58 print "\t %10.10s | %11.11s | %11.11s | %12s" % \
59 (plcnode['boot_state'], diff_time(plcnode['date_created']),
60 diff_time(plcnode['last_updated']),
61 diff_time(plcnode['last_contact']))
63 def fb_print_nodeinfo(fbnode):
65 if 'checked' in fbnode:
66 print "%11.11s " % diff_time(fbnode['checked'])
69 print "\t state | ssh | pcu | bootcd | category | kernel"
71 fbnode['bootcd'] = fbnode['bootcd'].split()[-1]
73 fbnode['bootcd'] = "unknown"
74 fbnode['kernel'] = fbnode['kernel'].split()[2]
75 print "\t %(state)10.10s | %(ssh)5.5s | %(pcu)5.5s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode
77 def act_print_nodeinfo(actnode, header):
79 print " Created: %11.11s" % diff_time(actnode['date_created'])
80 print " LastTime %11.11s" % diff_time(actnode['time'])
81 print "\t RT | category | action | msg"
85 print "\t %5.5s %5.5s | %8.8s | %15.15s | %s" % \
86 (actnode['rt']['Status'], actnode['rt']['id'][7:],
87 actnode['category'], actnode['action'][0],
88 actnode['msg_format'][:-1])
90 print "\t %5.5s | %8.8s | %15.15s | %s" % \
91 (actnode['ticket_id'],
92 actnode['category'], actnode['action'][0],
93 actnode['msg_format'][:-1])
95 def pcu_print_info(pcuinfo):
97 if 'checked' in pcuinfo:
98 print "%11.11s " % diff_time(pcuinfo['checked'])
102 print "\t user | password | hostname "
103 print "\t %17s | %17s | %30s | %s" % \
104 (pcuinfo['username'], pcuinfo['password'],
105 reboot.pcu_name(pcuinfo), pcuinfo['model'])
107 if pcuinfo['portstatus']['22'] == "open":
108 print "\t ssh -o PasswordAuthentication=yes -o PubkeyAuthentication=no %s@%s" % (pcuinfo['username'], reboot.pcu_name(pcuinfo))
109 if pcuinfo['portstatus']['23'] == "open":
110 print "\t telnet %s" % (reboot.pcu_name(pcuinfo))
111 if pcuinfo['portstatus']['80'] == "open" or \
112 pcuinfo['portstatus']['443'] == "open":
113 print "\t http://%s" % (reboot.pcu_name(pcuinfo))
116 plc_nodeinfo = api.GetNodes({'hostname': config.node}, None)[0]
117 fb_nodeinfo = fb['nodes'][config.node]['values']
119 plc_print_nodeinfo(plc_nodeinfo)
120 fb_print_nodeinfo(fb_nodeinfo)
122 if fb_nodeinfo['pcu'] == "PCU":
123 pcu = reboot.get_pcu_values(fb_nodeinfo['plcnode']['pcu_ids'][0])
126 if config.node in act_all and len(act_all[config.node]) > 0:
128 for act_nodeinfo in act_all[config.node]:
129 act_print_nodeinfo(act_nodeinfo, header)
130 else: act_nodeinfo = None