X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plcapi.py;h=acccda0e36d19afb3e8b024bdb34602f43808c13;hb=9e6b9c1ea9e020c55c85b433bac47231d63e9ffd;hp=03a9ca7af2bfe1c25fce346f7758df5863575d25;hpb=c484e6e613a4016d33471b517bc6298ca5b997d0;p=nodemanager.git diff --git a/plcapi.py b/plcapi.py index 03a9ca7..acccda0 100644 --- a/plcapi.py +++ b/plcapi.py @@ -1,7 +1,10 @@ -# $Id$ - import safexmlrpc -import hmac, sha +import hmac +try: + from hashlib import sha1 as sha +except ImportError: + import sha +import logger class PLCAPI: """ @@ -14,7 +17,7 @@ class PLCAPI: session => SessionAuth To authenticate using the Boot Manager authentication method, or - the new session-based method. + the new session-based method, respectively. """ def __init__(self, uri, cacert, auth, timeout = 90, **kwds): @@ -32,12 +35,10 @@ 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"): - # try authenticatipopulate /etc.planetlab/session + def update_session(self, f="/usr/boot/plnode.txt"): + # try authenticatipopulate /etc.planetlab/session def plnode(key): try: return [i[:-1].split('=') for i in open(f).readlines() if i.startswith(key)][0][1].strip('"') @@ -48,25 +49,17 @@ 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): - # 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" - + + + def check_authentication(self): + authstatus = False + if self.key or self.session: + try: + authstatus = self.AuthCheck() + except: + logger.log_exc("plcapi: failed in plcapi.check_authentication") + return authstatus + def add_auth(self, function): """