remove old blacklist
[monitor.git] / grouprins.py
index d859727..5529418 100755 (executable)
 #  * do something else to them all.
 # 
 
-import plc
+from monitor import config
+from monitor import util
+from monitor import const
+from monitor import database
+from monitor import parser as parsermodule
+from monitor import reboot
+from monitor.database.info.model import *
+from monitor.wrapper import plc
 api = plc.getAuthAPI()
 
 import traceback
-import config
-import util.file
 from optparse import OptionParser
 
-import const
-from nodecommon import *
+from monitor.common import *
 from nodequery import verify,query_to_dict,node_select
-import database
-from unified_model import *
+from monitor.model import *
 import os
 
 import time
-import parser as parsermodule
 
-from model import *
 import bootman                 # debug nodes
-import reboot          # down nodes without pcu
-import mailmonitor     # down nodes with pcu
-from emailTxt import mailtxt
-#reboot.verbose = 0
+import mailmonitor     # down nodes without pcu
+from monitor.wrapper.emailTxt import mailtxt
 import sys
 
 class Reboot(object):
@@ -75,6 +74,7 @@ class Reboot(object):
                                        return ret
 
                                except Exception,e:
+                                       email_exception()
                                        print traceback.print_exc(); print e
 
                                        # NOTE: this failure could be an implementation issue on
@@ -97,6 +97,7 @@ class Reboot(object):
                                        return ret
 
                                except Exception,e:
+                                       email_exception()
                                        print traceback.print_exc(); print e
 
                                        # NOTE: this failure could be an implementation issue on
@@ -140,6 +141,7 @@ class Reboot(object):
                try:
                        return mailmonitor.reboot(host)
                except Exception, e:
+                       email_exception(host)
                        print traceback.print_exc(); print e
                        return False
 
@@ -228,14 +230,20 @@ if config.nodegroup:
        nodelist = api.GetNodes(ng[0]['node_ids'])
        hostnames = [ n['hostname'] for n in nodelist ]
 
+if config.site:
+       site = api.GetSites(config.site)
+       l_nodes = api.GetNodes(site[0]['node_ids'], ['hostname'])
+       hostnames = [ n['hostname'] for n in l_nodes ]
+
 if config.node or config.nodelist:
        if config.node: hostnames = [ config.node ] 
        else: hostnames = util.file.getListFromFile(config.nodelist)
 
-fb = database.dbLoad("findbad")
+fbquery = FindbadNodeRecord.get_all_latest()
+fb_nodelist = [ n.hostname for n in fbquery ]
 
 if config.nodeselect:
-       hostnames = node_select(config.nodeselect, fb['nodes'].keys(), fb)
+       hostnames = node_select(config.nodeselect, fb_nodelist)
 
 if config.findbad:
        # rerun findbad with the nodes in the given nodes.
@@ -244,7 +252,8 @@ if config.findbad:
        os.system("./findbad.py --cachenodes --increment --nodelist %s" % file)
        # TODO: shouldn't we reload the node list now?
 
-l_blacklist = database.if_cached_else(1, "l_blacklist", lambda : [])
+q_blacklist = BlacklistRecord.query.all()
+l_blacklist = [ n.hostname for n in q_blacklist ]
 # commands:
 i = 1
 count = 1
@@ -257,6 +266,7 @@ for host in hostnames:
                try:
                        node = api.GetNodes(host)[0]
                except:
+                       email_exception()
                        print traceback.print_exc(); 
                        print "FAILED GETNODES for host: %s" % host
                        continue
@@ -281,6 +291,7 @@ for host in hostnames:
                                        # todo: send thank you, etc.
                                        mailmonitor.reboot(host)
                                except Exception, e:
+                                       email_exception()
                                        print traceback.print_exc(); print e
 
                                continue
@@ -339,10 +350,10 @@ for host in hostnames:
                                print "ALL METHODS OF RESTARTING %s FAILED" % host
                                args = {}
                                args['hostname'] = host
-                               m = PersistMessage(host, "ALL METHODS FAILED for %(hostname)s" % args,
-                                                                                        "CANNOT CONTACT", False, db='suspect_persistmessages')
-                               m.reset()
-                               m.send(['monitor-list@lists.planet-lab.org'])
+                               #m = PersistMessage(host, "ALL METHODS FAILED for %(hostname)s" % args,
+                               #                                                        "CANNOT CONTACT", False, db='suspect_persistmessages')
+                               #m.reset()
+                               #m.send(['monitor-list@lists.planet-lab.org'])
 
                        l = Log(host, record)
                        print l
@@ -351,6 +362,7 @@ for host in hostnames:
                print "Killed by interrupt"
                sys.exit(0)
        except:
+               email_exception()
                print traceback.print_exc();
                print "Continuing..."