loop on authcheck code in case session is wrong AND api is unavailable.
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Thu, 6 Aug 2009 20:21:20 +0000 (20:21 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Thu, 6 Aug 2009 20:21:20 +0000 (20:21 +0000)
nm.py
plcapi.py

diff --git a/nm.py b/nm.py
index ed5309e..85c9004 100755 (executable)
--- a/nm.py
+++ b/nm.py
@@ -134,6 +134,7 @@ def run():
         plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod/2)
 
         #check auth
+        logger.log("Checking Auth.")
         while plc.check_authentication() != True:
             try:
                 plc.update_session()
@@ -141,6 +142,7 @@ def run():
             except:
                 logger.log("Retry Failed.  Waiting")
             time.sleep(iperiod)
+        logger.log("Authentication Succeeded!")
 
 
         while True:
index 2ef5dc1..be77171 100644 (file)
--- a/plcapi.py
+++ b/plcapi.py
@@ -50,8 +50,13 @@ class PLCAPI:
 
         
     def check_authentication(self):
-        # just a simple call to check authentication
-        return self.AuthCheck(self)
+        authstatus = False
+        if self.key or self.session:
+            try: 
+                authstatus = self.AuthCheck()
+            except: 
+                logger.log_exc()
+        return authstatus
 
 
     def add_auth(self, function):