From: Faiyaz Ahmed Date: Thu, 6 Aug 2009 16:35:33 +0000 (+0000) Subject: Change plugin API (GetSlivers()) argument order to avoid unnecessary PLCAPI dependenc... X-Git-Tag: NodeManager-1.8-11~3 X-Git-Url: http://git.onelab.eu/?p=nodemanager.git;a=commitdiff_plain;h=7acb378c1b5448d23bd1eb0e6583a530604d0511 Change plugin API (GetSlivers()) argument order to avoid unnecessary PLCAPI dependency. Fixes Delegation. --- diff --git a/conf_files.py b/conf_files.py index 31c325c..b3b65f8 100644 --- a/conf_files.py +++ b/conf_files.py @@ -86,7 +86,7 @@ class conf_files: def start(options, config): pass -def GetSlivers(plc, data, config = None): +def GetSlivers(data, config = None, plc = None): logger.log("conf_files: Running.") cf = conf_files() cf.run_once(data) diff --git a/net.py b/net.py index 7c9242d..2d02905 100644 --- a/net.py +++ b/net.py @@ -16,7 +16,7 @@ import bwlimit, logger, iptables def start(options, conf): logger.log("net plugin starting up...") -def GetSlivers(plc, data, config): +def GetSlivers(data, config, plc): logger.verbose("net:GetSlivers called.") InitInterfaces(plc, data) # writes sysconfig files. if 'OVERRIDES' in dir(config): diff --git a/nm.py b/nm.py index c262906..ed5309e 100755 --- a/nm.py +++ b/nm.py @@ -54,7 +54,7 @@ if os.path.exists(options.path): modules = [] -def GetSlivers(plc, config): +def GetSlivers(config, plc): '''Run call backs defined in modules''' try: logger.log("Syncing w/ PLC") @@ -70,7 +70,7 @@ def GetSlivers(plc, config): for module in modules: try: callback = getattr(module, 'GetSlivers') - callback(plc, data, config) + callback(data, config, plc) except: logger.log_exc() @@ -133,10 +133,20 @@ def run(): irandom=int(options.random) plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod/2) + #check auth + while plc.check_authentication() != True: + try: + plc.update_session() + logger.log("Authentication Failure. Retrying") + except: + logger.log("Retry Failed. Waiting") + time.sleep(iperiod) + + while True: # Main NM Loop logger.verbose('mainloop - nm:getSlivers - period=%d random=%d'%(iperiod,irandom)) - GetSlivers(plc, config) + GetSlivers(config, plc) delay=iperiod + random.randrange(0,irandom) logger.verbose('mainloop - sleeping for %d s'%delay) time.sleep(delay) diff --git a/plcapi.py b/plcapi.py index 03a9ca7..2ef5dc1 100644 --- 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): """ diff --git a/plugins/codemux.py b/plugins/codemux.py index b367b58..3852aa2 100644 --- a/plugins/codemux.py +++ b/plugins/codemux.py @@ -14,7 +14,7 @@ CODEMUXCONF="/etc/codemux/codemux.conf" def start(options, conf): logger.log("codemux plugin starting up...") -def GetSlivers(plc, data, config): +def GetSlivers(data, config, plc = None): """ For each sliver with the codemux attribute, parse out "host,port" and make entry in conf. Restart service after. diff --git a/plugins/rawdisk.py b/plugins/rawdisk.py index b220a46..8124f67 100644 --- a/plugins/rawdisk.py +++ b/plugins/rawdisk.py @@ -46,7 +46,7 @@ def get_unused_devices(): partitions.close() return devices -def GetSlivers(plc, data, conf): +def GetSlivers(data, config=None, plc=None): if 'slivers' not in data: logger.log("sliverauth: getslivers data lack's sliver information. IGNORING!") return diff --git a/plugins/sliverauth.py b/plugins/sliverauth.py index ba1b30b..0cbc8ab 100644 --- a/plugins/sliverauth.py +++ b/plugins/sliverauth.py @@ -31,7 +31,7 @@ def SetSliverTag(plc, slice, tagname, value): slivertag_id=slivertags[0]['slice_tag_id'] plc.UpdateSliceTag(slivertag_id,value) -def GetSlivers(plc, data, conf): +def GetSlivers(data, config, plc): # XXX REMOVE ME logger.log("sliverauth: DISABLED!") return diff --git a/plugins/specialaccounts.py b/plugins/specialaccounts.py index 5debf95..545910f 100644 --- a/plugins/specialaccounts.py +++ b/plugins/specialaccounts.py @@ -21,8 +21,11 @@ import tools def start(options, conf): logger.log("personkeys plugin starting up...") -def GetSlivers(plc, data, conf): - if 'accounts' not in data: return +def GetSlivers(data, conf = None, plc = None): + if 'accounts' not in data: + logger.log("specialaccounts: No account information found. DISABLED!") + return + for account in data['accounts']: name = account['name'] new_keys = account['keys'] @@ -37,17 +40,17 @@ def GetSlivers(plc, data, conf): dot_ssh = os.path.join(pw_dir,'.ssh') if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh) auth_keys = os.path.join(dot_ssh,'authorized_keys') + logger.log("new keys = %s" % auth_keys) fd, fname = tempfile.mkstemp('','authorized_keys',dot_ssh) - for key in new_keys: + for key in new_keys: os.write(fd,key) os.write(fd,'\n') os.close(fd) - if os.path.exists(auth_keys): - os.unlink(auth_keys) - os.rename(fname,auth_keys) + if os.path.exists(auth_keys): os.unlink(auth_keys) + os.rename(fname, auth_keys) # set permissions properly os.chmod(dot_ssh, 0700) diff --git a/plugins/vsys.py b/plugins/vsys.py index a2bc2bb..927c7c1 100644 --- a/plugins/vsys.py +++ b/plugins/vsys.py @@ -13,7 +13,7 @@ VSYSBKEND="/vsys" def start(options, conf): logger.log("vsys plugin starting up...") -def GetSlivers(plc, data, config=None): +def GetSlivers(data, config=None, plc=None): """For each sliver with the vsys attribute, set the script ACL, create the vsys directory in the slice, and restart vsys.""" # Touch ACLs and create dict of available scripts = {} diff --git a/sm.py b/sm.py index 62de7f9..0b4d505 100644 --- a/sm.py +++ b/sm.py @@ -54,7 +54,7 @@ DEFAULT_ALLOCATION = { start_requested = False # set to True in order to request that all slivers be started @database.synchronized -def GetSlivers(plc, data, config = None, fullupdate=True): +def GetSlivers(data, config = None, plc=None, fullupdate=True): """This function has two purposes. One, convert GetSlivers() data into a more convenient format. Two, even if no updates are coming in, use the GetSlivers() heartbeat as a cue to scan for expired