X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=nodemanager.py;h=dfe62848755819ab2a2d5fe584efda6fdbb1090f;hb=643d1341e12c27bff66bb760194bd7d72622aae3;hp=c0a565625168cacf7b4a030de66365b3652be17a;hpb=9e596e6eb3c871ab25837903b0ed30f165d9d688;p=nodemanager.git diff --git a/nodemanager.py b/nodemanager.py index c0a5656..dfe6284 100755 --- a/nodemanager.py +++ b/nodemanager.py @@ -11,7 +11,7 @@ import optparse import time -import xmlrpclib +import xmlrpc.client import socket import os import sys @@ -77,7 +77,7 @@ class NodeManager: if os.path.exists(self.options.path): sys.path.append(self.options.path) plugins = [ os.path.split(os.path.splitext(x)[0])[1] - for x in glob.glob( os.path.join(self.options.path,'*.py') ) + for x in glob.glob( os.path.join(self.options.path, '*.py') ) if not x.endswith("/__init__.py") ] self.modules += plugins @@ -116,7 +116,7 @@ class NodeManager: try: callback = getattr(module, 'GetSlivers') module_data = data - if getattr(module,'persistent_data',False): + if getattr(module, 'persistent_data', False): module_data = last_data callback(data, config, plc) except SystemExit as e: @@ -157,7 +157,7 @@ class NodeManager: if att['tagname'] == 'vref': att['value'] = slicefamily continue - sliver['attributes'].append({ 'tagname':'vref','value':slicefamily}) + sliver['attributes'].append({ 'tagname':'vref', 'value':slicefamily}) except: logger.log_exc("nodemanager: Could not overwrite 'vref' attribute from 'GetSliceFamily'", name=sliver['name']) @@ -198,11 +198,11 @@ class NodeManager: try: other_pid = tools.pid_file() if other_pid != None: - print """There might be another instance of the node manager running as pid {}. -If this is not the case, please remove the pid file {}. -- exiting""".format(other_pid, tools.PID_FILE) + print("""There might be another instance of the node manager running as pid {}. +If this is not the case, please remove the pid file {}. -- exiting""".format(other_pid, tools.PID_FILE)) return - except OSError, err: - print "Warning while writing PID file:", err + except OSError as err: + print("Warning while writing PID file:", err) # load modules self.loaded_modules = [] @@ -222,7 +222,7 @@ If this is not the case, please remove the pid file {}. -- exiting""".format(oth # sort on priority (lower first) def module_priority (m): - return getattr(m,'priority',NodeManager.default_priority) + return getattr(m, 'priority', NodeManager.default_priority) self.loaded_modules.sort(key=module_priority) logger.log('ordered modules:') @@ -232,7 +232,8 @@ If this is not the case, please remove the pid file {}. -- exiting""".format(oth # Load /etc/planetlab/session if os.path.exists(self.options.session): - session = file(self.options.session).read().strip() + with open(self.options.session) as f: + session = f.read().strip() else: session = None @@ -250,7 +251,7 @@ If this is not the case, please remove the pid file {}. -- exiting""".format(oth try: plc.update_session() logger.log("nodemanager: Authentication Failure. Retrying") - except Exception,e: + except Exception as e: logger.log("nodemanager: Retry Failed. ({}); Waiting..".format(e)) time.sleep(iperiod) logger.log("nodemanager: Authentication Succeeded!") @@ -262,11 +263,11 @@ If this is not the case, please remove the pid file {}. -- exiting""".format(oth logger.log('nodemanager: mainloop - calling GetSlivers - period={} random={}' .format(iperiod, irandom)) self.GetSlivers(config, plc) - delay = iperiod + random.randrange(0,irandom) + delay = iperiod + random.randrange(0, irandom) work_end = time.time() work_duration = int(work_end-work_beg) logger.log('nodemanager: mainloop has worked for {} s - sleeping for {} s' - .format(work_duration,delay)) + .format(work_duration, delay)) time.sleep(delay) except SystemExit: pass