def __init__(self, options=None, config_file=None): # If no options have been provided, create an empty dict if not options: options = {} if cfg.CONF.core_plugin is None: msg = _('Crd core_plugin not configured!') LOG.critical(msg) raise Exception(msg) # NOTE(jkoelker) Testing for the subclass with the __subclasshook__ # breaks tach monitoring. It has been removed # intentianally to allow v2 plugins to be monitored # for performance metrics. plugin_provider = cfg.CONF.core_plugin LOG.debug(_("Plugin location: %s"), plugin_provider) # If the plugin can't be found let them know gracefully try: LOG.info(_("Loading Plugin: %s"), plugin_provider) plugin_klass = importutils.import_class(plugin_provider) except ClassNotFound: LOG.exception(_("Error loading plugin")) raise Exception(_("Plugin not found. You can install a " "plugin with: pip install <plugin-name>\n" "Example: pip install crd-sample-plugin")) self.plugin = plugin_klass() # core plugin as a part of plugin collection simplifies # checking extensions # TODO (enikanorov): make core plugin the same as # the rest of service plugins self.service_plugins = {constants.CORE: self.plugin} self._load_service_plugins() LOG.info(_("Loaded plugins %s"), str(self.service_plugins))
def __init__(self, host, binary, topic, manager, report_interval=None, periodic_interval=None, periodic_fuzzy_delay=None, *args, **kwargs): self.binary = binary self.manager_class_name = manager manager_class = importutils.import_class(self.manager_class_name) self.manager = manager_class(host=host, *args, **kwargs) self.report_interval = report_interval self.periodic_interval = periodic_interval self.periodic_fuzzy_delay = periodic_fuzzy_delay self.saved_args, self.saved_kwargs = args, kwargs self.timers = [] super(Service, self).__init__(host, topic, manager=self.manager)
def __init__(self, host=None): super(DhcpAgent, self).__init__(host=host) self.needs_resync = False self.conf = cfg.CONF self.cache = NetworkCache() self.root_helper = config.get_root_helper(self.conf) self.dhcp_driver_cls = importutils.import_class(self.conf.dhcp_driver) ctx = context.get_admin_context_without_session() self.plugin_rpc = DhcpPluginApi(topics.PLUGIN, ctx, self.conf.use_namespaces) # create dhcp dir to store dhcp info dhcp_dir = os.path.dirname("/%s/dhcp/" % self.conf.state_path) if not os.path.isdir(dhcp_dir): os.makedirs(dhcp_dir, 0o755) self.dhcp_version = self.dhcp_driver_cls.check_version() self._populate_networks_cache()
def _load_service_plugins(self): modconf = configparser.ConfigParser() confpath = cfg.CONF.config_file[0] confpath = confpath.replace('nscs.conf', 'modules/') confbase = os.path.dirname(confpath) moduleconfs = os.listdir(confbase) paths = '' for cnf in moduleconfs: if re.search(r'(\.conf)$', cnf): cnf = str(confpath+cnf) modconf.read(cnf) service_plugin = str(modconf.get("DEFAULT","service_plugins")) paths = paths+service_plugin+',' plugin_providers = paths.split(',') #plugin_providers = cfg.CONF.service_plugins LOG.debug(_("Loading service plugins: %s"), plugin_providers) for provider in plugin_providers: if provider == '': continue try: LOG.info(_("Loading Plugin: %s"), provider) plugin_class = importutils.import_class(provider) except ClassNotFound: LOG.exception(_("Error loading plugin")) raise Exception(_("Plugin not found.")) plugin_inst = plugin_class() # only one implementation of svc_type allowed # specifying more than one plugin # for the same type is a fatal exception if plugin_inst.get_plugin_type() in self.service_plugins: raise Exception(_("Multiple plugins for service " "%s were configured"), plugin_inst.get_plugin_type()) self.service_plugins[plugin_inst.get_plugin_type()] = plugin_inst LOG.debug(_("Successfully loaded %(type)s plugin. " "Description: %(desc)s"), {"type": plugin_inst.get_plugin_type(), "desc": plugin_inst.get_plugin_description()})
def _load_driver(self, driver_provider): LOG.debug(_("Driver location: %s"), driver_provider) plugin_klass = importutils.import_class(driver_provider) return plugin_klass(self.conf)