3 # Copyright (c) 2004 The Trustees of Princeton University (Trustees).
5 # Stephen Soltesz <soltesz@cs.princeton.edu>
7 # $Id: monitor.py,v 1.7 2007/07/03 19:59:02 soltesz Exp $
11 from monitor_policy import *
17 api = plc.PLC(auth.auth, auth.plc)
19 from clean_policy import *
22 print "calling reboot!!! %s " % hostname
24 l_nodes = api.GetNodes(hostname)
26 raise Exception("No such host: %s" % hostname)
28 l_blacklist = database.if_cached_else(1, "l_blacklist", lambda : [])
29 l_ticket_blacklist = database.if_cached_else(1,"l_ticket_blacklist",lambda : [])
31 l_nodes = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
33 raise Exception("Host removed via blacklist: %s" % hostname)
35 ad_dbTickets = database.if_cached_else_refresh(True, False, "ad_dbTickets", lambda : [])
36 if ad_dbTickets == None:
37 raise Exception("Could not find cached dbTickets")
39 print "starting new thing"
40 mon = MonitorMergeDiagnoseSendEscellate(hostname, True)
44 #merge = Merge( [node['hostname'] for node in l_nodes])
45 #record_list = merge.run()
47 #rt = RT(record_list, ad_dbTickets, l_ticket_blacklist)
48 #record_list = rt.run()
50 #diag = Diagnose(record_list)
51 #diagnose_out = diag.run()
54 #action = Action(diagnose_out)
59 def reboot2(hostname):
60 l_nodes = api.GetNodes(hostname)
62 raise Exception("No such host: %s" % hostname)
64 l_blacklist = database.if_cached_else(1, "l_blacklist", lambda : [])
65 l_ticket_blacklist = database.if_cached_else(1,"l_ticket_blacklist",lambda : [])
67 l_nodes = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
69 raise Exception("Host removed via blacklist: %s" % hostname)
71 ad_dbTickets = database.if_cached_else_refresh(True, False, "ad_dbTickets", lambda : None)
72 if ad_dbTickets == None:
73 raise Exception("Could not find cached dbTickets")
77 args['hostname'] = "%s" % hostname
78 args['hostname_list'] = "%s" % hostname
79 args['loginbase'] = plc.siteId(hostname)
81 m = PersistMessage(hostname, "Please Update Boot Image for %s" % hostname,
82 mailtxt.newalphacd_one[1] % args, True, db='bootcd_persistmessages')
85 merge = Merge( [node['hostname'] for node in l_nodes])
86 record_list = merge.run()
88 rt = RT(record_list, ad_dbTickets, l_ticket_blacklist)
89 record_list = rt.run()
91 diag = Diagnose(record_list)
92 diagnose_out = diag.run()
95 action = Action(diagnose_out)
102 for host in sys.argv[1:]:
105 if __name__ == '__main__':