(getattr(module, 'priority', NodeManager.default_priority), module.__name__)) # Load /etc/planetlab/session if os.path.exists(self.options.session): session = file(self.options.session).read().strip() else: session = None # get random periods iperiod = int(self.options.period) irandom = int(self.options.random) # Initialize XML-RPC client plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod / 2) #check auth logger.log("nodemanager: Checking Auth.") while plc.check_authentication() != True: try: plc.update_session() logger.log("nodemanager: Authentication Failure. Retrying") except Exception, e: logger.log("nodemanager: Retry Failed. (%r); Waiting.." % e) time.sleep(iperiod) logger.log("nodemanager: Authentication Succeeded!") while True:
for module in self.loaded_modules: logger.log ('%s: %s'%(getattr(module,'priority',NodeManager.default_priority),module.__name__)) # Load /etc/planetlab/session if os.path.exists(self.options.session): session = file(self.options.session).read().strip() else: session = None # get random periods iperiod=int(self.options.period) irandom=int(self.options.random) # Initialize XML-RPC client plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod/2) #check auth logger.log("nodemanager: Checking Auth.") while plc.check_authentication() != True: try: plc.update_session() logger.log("nodemanager: Authentication Failure. Retrying") except Exception,e: logger.log("nodemanager: Retry Failed. (%r); Waiting.."%e) time.sleep(iperiod) logger.log("nodemanager: Authentication Succeeded!") plc.__getattr__("GetSlices") while True: # Main nodemanager Loop
for module in self.loaded_modules: logger.log ('%s: %s'%(getattr(module,'priority',NodeManager.default_priority),module.__name__)) # Load /etc/planetlab/session if os.path.exists(self.options.session): session = file(self.options.session).read().strip() else: session = None # get random periods iperiod=int(self.options.period) irandom=int(self.options.random) # Initialize XML-RPC client plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod/2) #check auth logger.log("nodemanager: Checking Auth.") while plc.check_authentication() != True: try: plc.update_session() logger.log("nodemanager: Authentication Failure. Retrying") except Exception,e: logger.log("nodemanager: Retry Failed. (%r); Waiting.."%e) time.sleep(iperiod) logger.log("nodemanager: Authentication Succeeded!") while True: # Main nodemanager Loop
def run(self): # make sure to create /etc/planetlab/virt so others can read that # used e.g. in vsys-scripts's sliceip tools.get_node_virt() try: if self.options.daemon: tools.daemon() # set log level if self.options.verbose: logger.set_level(logger.LOG_VERBOSE) tools.init_signals() # Load /etc/planetlab/plc_config config = Config(self.options.config) try: other_pid = tools.pid_file() if other_pid is not 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)) return except OSError as err: print("Warning while writing PID file:", err) # load modules self.loaded_modules = [] for module in self.modules: try: m = __import__(module) logger.verbose("nodemanager: triggering {}.start".format(m.__name__)) try: m.start() except Exception: logger.log("WARNING: module {} did not start".format(m.__name__)) self.loaded_modules.append(m) except Exception: if module not in NodeManager.core_modules: logger.log_exc("ERROR while loading module {} - skipped" .format(module)) else: logger.log("FATAL : failed to start core module {}".format(module)) sys.exit(1) # sort on priority (lower first) def module_priority(module): return getattr(module, 'priority', NodeManager.default_priority) self.loaded_modules.sort(key=module_priority) logger.log('ordered modules:') for module in self.loaded_modules: logger.log('{}: {}' .format(getattr(module, 'priority', NodeManager.default_priority), module.__name__)) # Load /etc/planetlab/session if os.path.exists(self.options.session): with open(self.options.session) as feed: session = feed.read().strip() else: session = None # get random periods iperiod = int(self.options.period) irandom = int(self.options.random) # Initialize XML-RPC client plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod/2) #check auth logger.log("nodemanager: Checking Auth.") while not plc.check_authentication(): try: plc.update_session() logger.log("nodemanager: Authentication Failure. Retrying") except Exception as exc: logger.log("nodemanager: Retry Failed. ({}); Waiting.." .format(exc)) time.sleep(iperiod) logger.log("nodemanager: Authentication Succeeded!") while True: # Main nodemanager Loop work_beg = time.time() logger.log('nodemanager: mainloop - calling GetSlivers - period={} random={}' .format(iperiod, irandom)) self.GetSlivers(config, plc) 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)) time.sleep(delay) except SystemExit: pass except: logger.log_exc("nodemanager: failed in run")