From: Marc Fiuczynski Date: Thu, 9 Jul 2009 02:26:35 +0000 (+0000) Subject: Updated to pass plugins an API handle (plc) and the plc_config (config) in addition... X-Git-Tag: NodeManager-1.8-24~4 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=6cc33eb69e9e8f15b8dce3f69ae43975b57f80fd;p=nodemanager.git Updated to pass plugins an API handle (plc) and the plc_config (config) in addition to the data pulled down from GetSlivers; Also made known_modules (which are basically plugins) and plugins use the same function signature --- diff --git a/conf_files.py b/conf_files.py index fc90da2..31c325c 100644 --- a/conf_files.py +++ b/conf_files.py @@ -86,7 +86,7 @@ class conf_files: def start(options, config): pass -def GetSlivers(data, plc = None, config = None): +def GetSlivers(plc, data, config = None): logger.log("conf_files: Running.") cf = conf_files() cf.run_once(data) diff --git a/net.py b/net.py index 0c8b357..7c9242d 100644 --- a/net.py +++ b/net.py @@ -13,6 +13,9 @@ import sioc, plnet # local modules import bwlimit, logger, iptables +def start(options, conf): + logger.log("net plugin starting up...") + def GetSlivers(plc, data, config): logger.verbose("net:GetSlivers called.") InitInterfaces(plc, data) # writes sysconfig files. diff --git a/nm.py b/nm.py index 1dd1b67..62d9ece 100755 --- a/nm.py +++ b/nm.py @@ -24,12 +24,14 @@ import tools from config import Config from plcapi import PLCAPI import random -import net id="$Id$" savedargv = sys.argv[:] -known_modules=['conf_files', 'sm', 'bwmon', 'vsys', 'codemux'] +# NOTE: modules listed here should also be loaded in this order +known_modules=['net','conf_files', 'sm', 'bwmon'] + +plugin_path = "/usr/share/NodeManager/plugins" parser = optparse.OptionParser() parser.add_option('-d', '--daemon', action='store_true', dest='daemon', default=False, help='run daemonized') @@ -39,7 +41,9 @@ parser.add_option('-k', '--session', action='store', dest='session', default='/e parser.add_option('-p', '--period', action='store', dest='period', default=600, help='Polling interval (sec)') parser.add_option('-r', '--random', action='store', dest='random', default=301, help='Range for additional random polling interval (sec)') parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='more verbose log') -parser.add_option('-P', '--path', action='store', dest='path', default='/usr/share/NodeManager/plugins', help='Path to plugins directory') +parser.add_option('-P', '--path', action='store', dest='path', default=plugin_path, help='Path to plugins directory') + +# NOTE: BUG the 'help' for this parser.add_option() wont list plugins from the --path argument parser.add_option('-m', '--module', action='store', dest='module', default='', help='run a single module among '+' '.join(known_modules)) (options, args) = parser.parse_args() @@ -62,15 +66,11 @@ def GetSlivers(plc, config): # XXX So some modules can at least boostrap. logger.log("nm: Can't contact PLC to GetSlivers(). Continuing.") data = {} - # Set i2 ip list for nodes in I2 nodegroup - # and init network interfaces (unless overridden) - try: net.GetSlivers(plc, data, config) # TODO - num of args needs to be unified across mods. - except: logger.log_exc() - # All other callback modules + # Invoke GetSlivers() functions from the callback modules for module in modules: try: callback = getattr(module, 'GetSlivers') - callback(data, plc, config) + callback(plc, data, config) except: logger.log_exc() diff --git a/plugins/codemux.py b/plugins/codemux.py index aa29351..b367b58 100644 --- a/plugins/codemux.py +++ b/plugins/codemux.py @@ -11,11 +11,10 @@ from config import Config CODEMUXCONF="/etc/codemux/codemux.conf" -def start(options, config): - pass +def start(options, conf): + logger.log("codemux plugin starting up...") - -def GetSlivers(data, plc = None, config = None): +def GetSlivers(plc, data, config): """ For each sliver with the codemux attribute, parse out "host,port" and make entry in conf. Restart service after. diff --git a/plugins/vsys.py b/plugins/vsys.py index dad1b75..a2bc2bb 100644 --- a/plugins/vsys.py +++ b/plugins/vsys.py @@ -10,11 +10,10 @@ from sets import Set VSYSCONF="/etc/vsys.conf" VSYSBKEND="/vsys" -def start(options, config): - pass +def start(options, conf): + logger.log("vsys plugin starting up...") - -def GetSlivers(data, plc = None, config = None): +def GetSlivers(plc, data, config=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 5d5de69..62de7f9 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(data, plc = None, config = None, fullupdate=True): +def GetSlivers(plc, data, config = 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