5 api = plc.PLC(auth.auth, auth.plc)
8 fb = soltesz.dbLoad("findbad")
9 act_all = soltesz.dbLoad("act_all")
15 from nodecommon import *
17 from config import config
18 from optparse import OptionParser
20 parser = OptionParser()
21 parser.set_defaults(node=None, endrecord=False)
22 parser.add_option("", "--node", dest="node", metavar="nodename.edu",
23 help="A single node name to add to the nodegroup")
24 parser.add_option("", "--endrecord", dest="endrecord", action="store_true",
25 help="Force an end to the action record; to prompt Montior to start messaging again.")
26 parser.add_option("", "--bootcd", dest="bootcd", action="store_true",
27 help="A stock help message for fetching a new BootCD from the PLC GUI.")
28 config = config(parser)
31 def diff_time(timestamp):
35 diff = now - timestamp
36 # return the number of seconds as a difference from current time.
38 if diff < 60: # sec in min.
40 t_str = "%s sec ago" % t
41 elif diff < 60*60: # sec in hour
43 t_str = "%s min ago" % int(t)
44 elif diff < 60*60*24: # sec in day
46 t_str = "%s hours ago" % int(t)
47 elif diff < 60*60*24*7: # sec in week
48 t = diff // (60*60*24)
49 t_str = "%s days ago" % int(t)
50 elif diff < 60*60*24*30: # approx sec in month
51 t = diff // (60*60*24*7)
52 t_str = "%s weeks ago" % int(t)
53 elif diff > 60*60*24*30: # approx sec in month
54 t = diff // (60*60*24*7*30)
55 t_str = "%s months ago" % int(t)
58 def plc_print_nodeinfo(plcnode):
59 url = "https://www.planet-lab.org/db/nodes/index.php?nodepattern="
60 plcnode['url'] = url + plcnode['hostname']
62 print "%(hostname)s %(url)s" % plcnode
63 print " Checked: %s" % time.ctime()
65 print "\t boot_state | created | updated | last_contact | key"
66 print "\t %5s | %11.11s | %11.11s | %12s | %s" % \
67 (color_boot_state(plcnode['boot_state']), diff_time(plcnode['date_created']),
68 diff_time(plcnode['last_updated']),
69 diff_time(plcnode['last_contact']), plcnode['key'])
71 def fb_print_nodeinfo(fbnode):
73 if 'checked' in fbnode:
74 print "%11.11s " % diff_time(fbnode['checked'])
77 print "\t state | ssh | pcu | bootcd | category | kernel"
79 fbnode['bootcd'] = fbnode['bootcd'].split()[-1]
81 fbnode['bootcd'] = "unknown"
83 fbnode['state'] = color_boot_state(get_current_state(fbnode))
85 fbnode['state'] = "none"
86 fbnode['kernel'] = fbnode['kernel'].split()[2]
87 print "\t %(state)5s | %(ssh)5.5s | %(pcu)5.5s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode
89 def act_print_nodeinfo(actnode, header):
91 if 'date_created' in actnode:
92 print " Created: %11.11s" % diff_time(actnode['date_created'])
93 print " LastTime %11.11s" % diff_time(actnode['time'])
94 print "\t RT | category | action | msg"
97 if 'rt' in actnode and 'Status' in actnode['rt']:
98 print "\t %5.5s %5.5s | %8.8s | %15.15s | %s" % \
99 (actnode['rt']['Status'], actnode['rt']['id'][7:],
100 actnode['category'], actnode['action'][0],
101 actnode['msg_format'][:-1])
103 if type(actnode['action']) == type([]):
104 action = actnode['action'][0]
106 action = actnode['action']
107 if 'category' in actnode:
108 category = actnode['category']
112 if 'msg_format' in actnode:
113 print "\t %5.5s | %8.8s | %15.15s | %s" % \
114 (actnode['ticket_id'],
116 actnode['msg_format'][:-1])
118 print "\t %5.5s | %8.8s | %15.15s" % \
119 (actnode['ticket_id'],
122 def pcu_print_info(pcuinfo, hostname):
124 if 'checked' in pcuinfo:
125 print "%11.11s " % diff_time(pcuinfo['checked'])
129 print "\t user | password | port | pcu_id | hostname "
130 print "\t %17s | %17s | %4s | %6s | %30s | %s" % \
131 (pcuinfo['username'], pcuinfo['password'],
132 pcuinfo[hostname], pcuinfo['pcu_id'], reboot.pcu_name(pcuinfo), pcuinfo['model'])
134 if 'portstatus' in pcuinfo and pcuinfo['portstatus'] != {} and pcuinfo['portstatus'] != None:
135 if pcuinfo['portstatus']['22'] == "open":
136 print "\t ssh -o PasswordAuthentication=yes -o PubkeyAuthentication=no %s@%s" % (pcuinfo['username'], reboot.pcu_name(pcuinfo))
137 if pcuinfo['portstatus']['23'] == "open":
138 print "\t telnet %s" % (reboot.pcu_name(pcuinfo))
139 if pcuinfo['portstatus']['80'] == "open" or \
140 pcuinfo['portstatus']['443'] == "open":
141 print "\t http://%s" % (reboot.pcu_name(pcuinfo))
142 if pcuinfo['portstatus']['443'] == "open":
143 print "\t racadm.py -r %s -u %s -p '%s'" % (pcuinfo['ip'], pcuinfo['username'], pcuinfo['password'])
144 print "\t cmdhttps/locfg.pl -s %s -f iloxml/Reset_Server.xml -u %s -p '%s' | grep MESSAGE" % \
145 (reboot.pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password'])
147 for node in config.args:
150 plc_nodeinfo = api.GetNodes({'hostname': config.node}, None)[0]
151 fb_nodeinfo = fb['nodes'][config.node]['values']
153 plc_print_nodeinfo(plc_nodeinfo)
154 fb_print_nodeinfo(fb_nodeinfo)
156 if fb_nodeinfo['pcu'] == "PCU":
157 pcu = reboot.get_pcu_values(fb_nodeinfo['plcnode']['pcu_ids'][0])
158 pcu_print_info(pcu, config.node)
160 if config.node in act_all and len(act_all[config.node]) > 0:
164 node_end_record(config.node)
165 #a = Action(config.node, act_all[config.node][0])
167 #a.delField('found_rt_ticket')
168 #a.delField('second-mail-at-oneweek')
169 #a.delField('second-mail-at-twoweeks')
170 #a.delField('first-found')
172 #rec['action'] = ["close_rt"]
173 #rec['category'] = "UNKNOWN"
174 #rec['stage'] = "monitor-end-record"
175 #rec['time'] = time.time() - 7*60*60*24
176 #act_all[config.node].insert(0,rec)
177 #soltesz.dbDump("act_all", act_all)
179 for act_nodeinfo in act_all[config.node]:
180 act_print_nodeinfo(act_nodeinfo, header)
181 else: act_nodeinfo = None
187 If you need a new bootcd, the steps are very simple:
190 * https://www.planet-lab.org/db/nodes/index.php?nodepattern=%s
191 * Select Download -> Download ISO image for %s
192 * Save the ISO, and burn it to a writable CD-ROM.
193 * Replace the old CD and reboot the machine.
195 Please let me know if you have any additional questions.
196 """ % (config.node, config.node)