def __init__(self, repo, plugins, password, encoding, cfile='/etc/bcfg2.conf', ca=None, setup=None, filemonitor='default', start_fam_thread=False): Component.__init__(self) self.datastore = repo try: fm = Bcfg2.Server.FileMonitor.available[filemonitor] except KeyError: logger.error("File monitor driver %s not available; " "forcing to default" % filemonitor) fm = Bcfg2.Server.FileMonitor.available['default'] famargs = dict(ignore=[], debug=False) if 'ignore' in setup: famargs['ignore'] = setup['ignore'] if 'debug' in setup: famargs['debug'] = setup['debug'] try: self.fam = fm(**famargs) except IOError: logger.error("Failed to instantiate fam driver %s" % filemonitor, exc_info=1) raise CoreInitError("Failed to instantiate fam driver (used %s)" % filemonitor) self.pubspace = {} self.cfile = cfile self.cron = {} self.plugins = {} self.plugin_blacklist = {} self.revision = '-1' self.password = password self.encoding = encoding self.setup = setup atexit.register(self.shutdown) # Create an event to signal worker threads to shutdown self.terminate = threading.Event() if '' in plugins: plugins.remove('') for plugin in plugins: if not plugin in self.plugins: self.init_plugins(plugin) # Remove blacklisted plugins for p, bl in list(self.plugin_blacklist.items()): if len(bl) > 0: logger.error("The following plugins conflict with %s;" "Unloading %s" % (p, bl)) for plug in bl: del self.plugins[plug] # This section logs the experimental plugins expl = [plug for (name, plug) in list(self.plugins.items()) if plug.experimental] if expl: logger.info("Loading experimental plugin(s): %s" % \ (" ".join([x.name for x in expl]))) logger.info("NOTE: Interfaces subject to change") # This section logs the deprecated plugins depr = [plug for (name, plug) in list(self.plugins.items()) if plug.deprecated] if depr: logger.info("Loading deprecated plugin(s): %s" % \ (" ".join([x.name for x in depr]))) mlist = self.plugins_by_type(Bcfg2.Server.Plugin.Metadata) if len(mlist) == 1: self.metadata = mlist[0] else: logger.error("No Metadata Plugin loaded; failed to instantiate Core") raise CoreInitError("No Metadata Plugin") self.statistics = self.plugins_by_type(Bcfg2.Server.Plugin.Statistics) self.pull_sources = self.plugins_by_type(Bcfg2.Server.Plugin.PullSource) self.generators = self.plugins_by_type(Bcfg2.Server.Plugin.Generator) self.structures = self.plugins_by_type(Bcfg2.Server.Plugin.Structure) self.connectors = self.plugins_by_type(Bcfg2.Server.Plugin.Connector) self.ca = ca self.fam_thread = threading.Thread(target=self._file_monitor_thread) if start_fam_thread: self.fam_thread.start() self.monitor_cfile()
def __init__(self, repo, plugins, password, encoding, cfile='/etc/bcfg2.conf', ca=None, filemonitor='default', start_fam_thread=False): Component.__init__(self) self.datastore = repo if filemonitor not in Bcfg2.Server.FileMonitor.available: logger.error("File monitor driver %s not available; forcing to default" % filemonitor) filemonitor = 'default' try: self.fam = Bcfg2.Server.FileMonitor.available[filemonitor]() except IOError: logger.error("Failed to instantiate fam driver %s" % filemonitor, exc_info=1) raise CoreInitError, "failed to instantiate fam driver (used %s)" % \ filemonitor self.pubspace = {} self.cfile = cfile self.cron = {} self.plugins = {} self.revision = '-1' self.password = password self.encoding = encoding atexit.register(self.shutdown) if '' in plugins: plugins.remove('') for plugin in plugins: if not plugin in self.plugins: self.init_plugins(plugin) expl = [plug for (name, plug) in self.plugins.iteritems() if plug.experimental] if expl: logger.info("Loading experimental plugin(s): %s" % \ (" ".join([x.name for x in expl]))) logger.info("NOTE: Interfaces subject to change") depr = [plug for (name, plug) in self.plugins.iteritems() if plug.deprecated] if depr: logger.info("Loading deprecated plugin(s): %s" % \ (" ".join([x.name for x in depr]))) mlist = [p for p in self.plugins.values() if \ isinstance(p, Bcfg2.Server.Plugin.Metadata)] if len(mlist) == 1: self.metadata = mlist[0] else: logger.error("No Metadata Plugin loaded; failed to instantiate Core") raise CoreInitError, "No Metadata Plugin" self.statistics = [plugin for plugin in self.plugins.values() if \ isinstance(plugin, Bcfg2.Server.Plugin.Statistics)] self.pull_sources = [plugin for plugin in self.statistics if \ isinstance(plugin, Bcfg2.Server.Plugin.PullSource)] self.generators = [plugin for plugin in self.plugins.values() if \ isinstance(plugin, Bcfg2.Server.Plugin.Generator)] self.structures = [plugin for plugin in self.plugins.values() if \ isinstance(plugin, Bcfg2.Server.Plugin.Structure)] self.connectors = [plugin for plugin in self.plugins.values() if \ isinstance(plugin, Bcfg2.Server.Plugin.Connector)] self.ca = ca self.fam_thread = threading.Thread(target=self._file_monitor_thread) if start_fam_thread: self.fam_thread.start()
def __init__(self, repo, plugins, password, encoding, cfile='/etc/bcfg2.conf', ca=None, filemonitor='default', start_fam_thread=False): Component.__init__(self) self.datastore = repo if filemonitor not in Bcfg2.Server.FileMonitor.available: logger.error("File monitor driver %s not available; " "forcing to default" % filemonitor) filemonitor = 'default' try: self.fam = Bcfg2.Server.FileMonitor.available[filemonitor]() except IOError: logger.error("Failed to instantiate fam driver %s" % filemonitor, exc_info=1) raise CoreInitError("failed to instantiate fam driver (used %s)" % \ filemonitor) self.pubspace = {} self.cfile = cfile self.cron = {} self.plugins = {} self.plugin_blacklist = {} self.revision = '-1' self.password = password self.encoding = encoding atexit.register(self.shutdown) # Create an event to signal worker threads to shutdown self.terminate = threading.Event() if '' in plugins: plugins.remove('') for plugin in plugins: if not plugin in self.plugins: self.init_plugins(plugin) # Remove blacklisted plugins for p, bl in list(self.plugin_blacklist.items()): if len(bl) > 0: logger.error("The following plugins conflict with %s;" "Unloading %s" % (p, bl)) for plug in bl: del self.plugins[plug] # This section logs the experimental plugins expl = [ plug for (name, plug) in list(self.plugins.items()) if plug.experimental ] if expl: logger.info("Loading experimental plugin(s): %s" % \ (" ".join([x.name for x in expl]))) logger.info("NOTE: Interfaces subject to change") # This section logs the deprecated plugins depr = [ plug for (name, plug) in list(self.plugins.items()) if plug.deprecated ] if depr: logger.info("Loading deprecated plugin(s): %s" % \ (" ".join([x.name for x in depr]))) mlist = self.plugins_by_type(Bcfg2.Server.Plugin.Metadata) if len(mlist) == 1: self.metadata = mlist[0] else: logger.error( "No Metadata Plugin loaded; failed to instantiate Core") raise CoreInitError("No Metadata Plugin") self.statistics = self.plugins_by_type(Bcfg2.Server.Plugin.Statistics) self.pull_sources = self.plugins_by_type( Bcfg2.Server.Plugin.PullSource) self.generators = self.plugins_by_type(Bcfg2.Server.Plugin.Generator) self.structures = self.plugins_by_type(Bcfg2.Server.Plugin.Structure) self.connectors = self.plugins_by_type(Bcfg2.Server.Plugin.Connector) self.ca = ca self.fam_thread = threading.Thread(target=self._file_monitor_thread) if start_fam_thread: self.fam_thread.start()