Change plugin API (GetSlivers()) argument order to avoid unnecessary PLCAPI dependenc...
[nodemanager.git] / plcapi.py
index 03a9ca7..2ef5dc1 100644 (file)
--- a/plcapi.py
+++ b/plcapi.py
@@ -2,6 +2,7 @@
 
 import safexmlrpc
 import hmac, sha
+import logger
 
 class PLCAPI:
     """
@@ -32,11 +33,9 @@ class PLCAPI:
             self.node_id = self.key = self.session = None
 
         self.server = safexmlrpc.ServerProxy(self.uri, self.cacert, self.timeout, allow_none = 1, **kwds)
-        
-        self.__check_authentication()
 
 
-    def __update_session(self, f="/usr/boot/plnode.txt"):
+    def update_session(self, f="/usr/boot/plnode.txt"):
         # try authenticatipopulate /etc.planetlab/session 
         def plnode(key):
             try:
@@ -48,25 +47,12 @@ class PLCAPI:
         plc = PLCAPI(self.uri, self.cacert, auth, self.timeout)
         open("/etc/planetlab/session", 'w').write(plc.GetSession().strip())
         self.session = open("/etc/planetlab/session").read().strip()
+
         
-    def __check_authentication(self):
+    def check_authentication(self):
         # just a simple call to check authentication
-        def check():
-            if (self.node_id and self.key) or self.session:
-                try:
-                    if self.AuthCheck() == 1: return True
-                except:
-                    return False
-            return False
-        if not check():
-            if self.node_id and self.key:
-                # if hmac fails, just make it fail
-                raise Exception, "Unable to authenticate with hmac"
-            else:
-                self.__update_session()
-                if not check():
-                    raise Exception, "Unable to authenticate with session"
-    
+        return self.AuthCheck(self)
+
 
     def add_auth(self, function):
         """