def loadPlugin(self, name, paths): for p in paths: path = os.path.join(p, name) if os.path.isdir(path): codeFile = os.path.join(path, "code.py") if os.path.isfile(codeFile): ##logger.debug("Plugin '{0}': Will load code from '{1}'".format(name, codeFile)) module = imp.load_source(name, codeFile) pluginClass = None for _, obj in inspect.getmembers(module): if inspect.isclass(obj): #logger.debug("Name: {0} Obj:{1}".format('className', obj)) bases = obj.__bases__ for base in bases: if base == Plugin: pluginClass = obj if pluginClass == None: misc.ERROR( "Invalid plugin '{0}' code.py: Missing MyPlugin(Plugin) class" .format(name)) else: #logger.debug("Plugin '{0}': Found class {1}".format(name, str(pluginClass))) plugin = pluginClass(name, path, self) logger.debug( "Loaded plugin '{0}' with 'code.py' module (path:'{1}')" .format(name, path)) else: # Plugin without code (Impossible since plugin refactoring. Kept in cases) logger.debug( "Loaded plugin '{0}' without 'code.py' module (path:'{1}')" .format(name, path)) plugin = Plugin(name, path, self) self.plugins.append(plugin) self.pluginByName[plugin.name] = plugin return misc.ERROR( "Unable to find a plugin of name '{0}' in plugin paths {1}".format( name, paths))
def __init__(self, name, path, context): Plugin.__init__(self, name, path, context)
def __init__(self, name, path, context): Plugin.__init__(self, name, path, context) self.myHostGroups = []