#!/usr/bin/python
#
-# $Id$
-# $URL$
-#
# Useful information can be found at https://svn.planet-lab.org/wiki/NodeManager
#
import socket
import os
import sys
-import resource
import glob
import pickle
+import random
+import resource
import logger
import tools
from config import Config
from plcapi import PLCAPI
-import random
class NodeManager:
parser = optparse.OptionParser()
parser.add_option('-d', '--daemon', action='store_true', dest='daemon', default=False,
help='run daemonized')
- parser.add_option('-s', '--startup', action='store_true', dest='startup', default=False,
- help='run all sliver startup scripts')
parser.add_option('-f', '--config', action='store', dest='config', default='/etc/planetlab/plc_config',
help='PLC configuration file')
parser.add_option('-k', '--session', action='store', dest='session', default='/etc/planetlab/session',
# Deal with plugins directory
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') ) ]
+ plugins = [ os.path.split(os.path.splitext(x)[0])[1]
+ for x in glob.glob( os.path.join(self.options.path,'*.py') )
+ if not x.endswith("/__init__.py")
+ ]
self.modules += plugins
if self.options.user_module:
assert self.options.user_module in self.modules
return {}
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()
try:
m = __import__(module)
logger.verbose("nodemanager: triggering %s.start"%m.__name__)
- m.start(self.options, config)
+ m.start()
self.loaded_modules.append(m)
except ImportError, err:
- print "Warning while loading module %s:" % module, err
+ logger.log_exc ("ERROR while loading module %s - skipping:" % module)
+ # if we fail to load any of these, it's really no need to go on any further
+ if module in NodeManager.core_modules:
+ logger.log("FATAL : failed to load core module %s"%module)
+ except AttributeError, err:
+ # triggered when module doesn't have a 'start' method
+ logger.log_exc ("ERROR while starting module %s - skipping:" % module)
+ # if we fail to load any of these, it's really no need to go on any further
+ if module in NodeManager.core_modules:
+ logger.log("FATAL : failed to start core module %s"%module)
# sort on priority (lower first)
def sort_module_priority (m1,m2):
while True:
# Main nodemanager Loop
+ work_beg=time.time()
logger.log('nodemanager: mainloop - calling GetSlivers - period=%d random=%d'%(iperiod,irandom))
self.GetSlivers(config, plc)
delay=iperiod + random.randrange(0,irandom)
- logger.log('nodemanager: mainloop - sleeping for %d s'%delay)
+ work_end=time.time()
+ work_duration=int(work_end-work_beg)
+ logger.log('nodemanager: mainloop has worked for %s s - sleeping for %d s'%(work_duration,delay))
time.sleep(delay)
except: logger.log_exc("nodemanager: failed in run")