- set API URL to www.planet-lab.org
[monitor.git] / policy.py
index 1af7ab7..81fa2c8 100644 (file)
--- a/policy.py
+++ b/policy.py
@@ -3,7 +3,7 @@
 #
 # Faiyaz Ahmed <faiyaza@cs.princeton.edu>
 #
-# $Id: policy.py,v 1.4 2006/11/14 19:20:13 faiyaza Exp $
+# $Id: policy.py,v 1.9 2007/01/17 19:46:40 faiyaza Exp $
 #
 # Policy Engine.
 
@@ -27,7 +27,7 @@ logger = logging.getLogger("monitor")
 POLSLEEP = 7200
 
 # Where to email the summary
-SUMTO = "pupadm@lists.planet-lab.org"
+SUMTO = "faiyaza@cs.princeton.edu"
 TECHEMAIL="tech-%s@sites.planet-lab.org"
 PIEMAIL="pi-%s@sites.planet-lab.org"
 SLICEMAIL="%s@slices.planet-lab.org"
@@ -35,7 +35,7 @@ PLCEMAIL="support@planet-lab.org"
 
 #Thresholds (DAYS)
 SPERDAY = 86400
-PITHRESH = 1 * SPERDAY
+PITHRESH = 2 * SPERDAY
 SLICETHRESH = 5 * SPERDAY
 # Days before attempting rins again
 RINSTHRESH = 5 * SPERDAY
@@ -80,7 +80,7 @@ class Policy(Thread):
                                        logger.info("POLICY:  %s in dbg, but acted on %s days ago" % (node, delta // SPERDAY))
                                        return
                        logger.info("POLICY:  Node in dbg - " + node)
-                       plc.nodeBootState(node, "rins") 
+                       plc.nodeBootState([node, "rins"])       
                        # If it has a PCU
                        return reboot.reboot(node)
        
@@ -107,7 +107,10 @@ class Policy(Thread):
                # Grab a node from the queue (pushed by rt thread).
                node = self.sickNoTicket.get(block = True)
                # Get the login base    
-               loginbase = plc.siteId(node)
+               loginbase = plc.siteId([node])
+               
+               # Princeton Backdoor
+               if loginbase == "princeton": return
 
                # Send appropriate message for node if in appropriate bucket.
                # If we know where to send a message
@@ -141,13 +144,16 @@ class Policy(Thread):
 
                                logger.info("POLICY:  acted %s on %s days ago" % (node, 
                                delta // SPERDAY))
+                       
+                               # If no luck with tech, email PI
+                               if (delta >= 1):
+                                       target.append(PIEMAIL % loginbase)
 
                                # If more than PI thresh, but less than slicethresh
                                if (delta >= PITHRESH) and (delta < SLICETHRESH): 
-                                       target.append(PIEMAIL % loginbase)
                                        #remove slice creation if enough nodes arent up
                                        if not self.enoughUp(loginbase):
-                                               slices = plc.slices(loginbase)
+                                               slices = plc.slices([loginbase])
                                                if len(slices) >= 1:
                                                        for slice in slices:
                                                                target.append(SLICEMAIL % slice)
@@ -155,16 +161,19 @@ class Policy(Thread):
                                                tmp = emailTxt.mailtxt.removedSliceCreation
                                                sbj = tmp[0] 
                                                msg = tmp[1] % {'loginbase': loginbase}
-                                               plc.removeSliceCreation(node)
+                                               plc.removeSliceCreation([node])
                                                mailer.email(sbj, msg, target)  
                                                self.squeezed[loginbase] = (time.time(), "creation")
+                                               self.emailed[node] = ("creation", time.time())  
+                                               logger.info("POLICY: Emailing (%s) %s - %s"\
+                                                       %("creation", node, target))
                                                return
 
                                # If more than PI thresh and slicethresh
                                if (delta >= PITHRESH) and (delta > SLICETHRESH):
                                        target.append(PIEMAIL % loginbase)
                                        # Email slices at site.
-                                       slices = plc.slices(loginbase)
+                                       slices = plc.slices([loginbase])
                                        if len(slices) >= 1:
                                                for slice in slices:
                                                        target.append(SLICEMAIL % slice)
@@ -174,9 +183,13 @@ class Policy(Thread):
                                                tmp = emailTxt.mailtxt.suspendSlices
                                                sbj = tmp[0] 
                                                msg = tmp[1] % {'loginbase': loginbase}
-                                               plc.suspendSlices(node)
+                                               plc.suspendSlices([node])
                                                self.squeezed[loginbase] = (time.time(), "freeze")
                                                mailer.email(sbj, msg, target)  
+                                               self.emailed[node] = ("freeze", time.time())
+                                               logger.info("POLICY: Emailing (%s) %s - %s"\
+                                                       %("freeze", node, target))
+
                                                return
 
                        # Find the bucket the node is in and send appropriate email
@@ -234,7 +247,7 @@ class Policy(Thread):
        Returns True if more than MINUP nodes are up at a site.
        '''
        def enoughUp(self, loginbase):
-               allsitenodes = plc.getSiteNodes(loginbase)
+               allsitenodes = plc.getSiteNodes([loginbase])
                if len(allsitenodes) == 0:
                        logger.info("Node not in db")
                        return
@@ -280,7 +293,7 @@ def main():
        #a.emailedStore("LOAD")
        #print a.emailed
 
-       print plc.slices(plc.siteId("alice.cs.princeton.edu"))
+       print plc.slices([plc.siteId(["alice.cs.princeton.edu"])])
        os._exit(0)
 if __name__ == '__main__':
        import os