def is_trunk_service_loaded(): for service_plugins in cfg.CONF.service_plugins: try: klass = runtime.load_class_by_alias_or_classname( 'neutron.service_plugins', service_plugins) if klass.__name__ == 'TrunkPlugin': return True except ImportError: continue return False
def load_and_init_conntrack_driver(*args, **kwargs): driver = cfg.CONF.fwaas.conntrack_driver try: conntrack_driver_cls = runtime.load_class_by_alias_or_classname( 'neutron.agent.l3.firewall_drivers', driver) except ImportError: with excutils.save_and_reraise_exception(): LOG.exception("Driver '%s' not found.", driver) conntrack_driver = conntrack_driver_cls() conntrack_driver.initialize(*args, **kwargs) return conntrack_driver
def load_and_init_conntrack_driver(*args, **kwargs): driver = cfg.CONF.fwaas.conntrack_driver try: conntrack_driver_cls = runtime.load_class_by_alias_or_classname( 'neutron.agent.l3.firewall_drivers', driver) except ImportError: with excutils.save_and_reraise_exception(): LOG.exception("Driver '%s' not found.", driver) conntrack_driver = conntrack_driver_cls() conntrack_driver.initialize(*args, **kwargs) return conntrack_driver
def _load_firewall_extension_driver(namespace, driver): """Loads driver using alias or class name :param namespace: namespace where alias is defined :param driver: driver alias or class name :returns driver that is loaded :raises ImportError if fails to load driver """ try: return runtime.load_class_by_alias_or_classname(namespace, driver) except ImportError: with excutils.save_and_reraise_exception(): LOG.error("Driver '%s' not found.", driver)
def _load_port_forwarding_class(): """Load port forwarding plugin :returns: instance of plugin that is loaded :raises ImportError: if fails to load plugin """ try: loaded_class = runtime.load_class_by_alias_or_classname( 'neutron.service_plugins', 'port_forwarding') return loaded_class() except ImportError: with excutils.save_and_reraise_exception(): LOG.error("Error loading port_forwarding plugin")
def load_interface_driver(conf): """Load interface driver for agents like DHCP or L3 agent. :param conf: driver configuration object :raises SystemExit of 1 if driver cannot be loaded """ try: loaded_class = runtime.load_class_by_alias_or_classname( INTERFACE_NAMESPACE, conf.interface_driver) return loaded_class(conf) except ImportError: LOG.error("Error loading interface driver '%s'", conf.interface_driver) raise SystemExit(1)
def __init__(self): super(TricirclePlugin, self).__init__() core_plugins_namespace = 'neutron.core_plugins' plugin_provider = cfg.CONF.tricircle.real_core_plugin plugin_class = runtime.load_class_by_alias_or_classname( core_plugins_namespace, plugin_provider) self.core_plugin = plugin_class() self.neutron_handle = resource_handle.NeutronResourceHandle( cfg.CONF.client.auth_url) self.neutron_handle.endpoint_url = \ cfg.CONF.tricircle.central_neutron_url self.on_trunk_create = {} self.on_subnet_delete = {} neutronclient.USER_AGENT = t_constants.LOCAL
def __init__(self): super(TricirclePlugin, self).__init__() core_plugins_namespace = 'neutron.core_plugins' plugin_provider = cfg.CONF.tricircle.real_core_plugin plugin_class = runtime.load_class_by_alias_or_classname( core_plugins_namespace, plugin_provider) self.core_plugin = plugin_class() self.neutron_handle = resource_handle.NeutronResourceHandle( cfg.CONF.client.auth_url) self.neutron_handle.endpoint_url = \ cfg.CONF.tricircle.central_neutron_url self.on_trunk_create = {} self.on_subnet_delete = {} neutronclient.USER_AGENT = t_constants.LOCAL
def get_bridge_manager(conf): """Get Bridge Manager. :param conf: bridge manager configuration object :raises SystemExit of 1 if driver cannot be loaded """ try: loaded_class = runtime.load_class_by_alias_or_classname( bridge_manager.BRIDGE_MANAGER_NAMESPACE, conf.bridge_manager) return loaded_class() except ImportError: LOG.error(_("Error loading bridge manager '%s'"), conf.bridge_manager) raise SystemExit(1)
def load_metering_driver(plugin, conf): """Load metering driver :param plugin: the metering plugin :param conf: driver configuration object :raises SystemExit of 1 if driver cannot be loaded """ try: loaded_class = runtime.load_class_by_alias_or_classname( METERING_NAMESPACE, conf.driver) return loaded_class(plugin, conf) except ImportError: LOG.error("Error loading metering driver '%s'", conf.driver) raise SystemExit(1)
def load_class_for_provider(namespace, plugin_provider): """Loads plugin using alias or class name :param namespace: namespace where alias is defined :param plugin_provider: plugin alias or class name :returns: plugin that is loaded :raises ImportError: if fails to load plugin """ try: return runtime.load_class_by_alias_or_classname( namespace, plugin_provider) except ImportError: with excutils.save_and_reraise_exception(): LOG.error("Plugin '%s' not found.", plugin_provider)
def load_class_for_provider(namespace, plugin_provider): """Loads plugin using alias or class name :param namespace: namespace where alias is defined :param plugin_provider: plugin alias or class name :returns: plugin that is loaded :raises ImportError: if fails to load plugin """ try: return runtime.load_class_by_alias_or_classname(namespace, plugin_provider) except ImportError: with excutils.save_and_reraise_exception(): LOG.error("Plugin '%s' not found.", plugin_provider)
def load_interface_driver(conf): """Load interface driver for agents like DHCP or L3 agent. :param conf: driver configuration object :raises SystemExit of 1 if driver cannot be loaded """ try: loaded_class = runtime.load_class_by_alias_or_classname( INTERFACE_NAMESPACE, conf.interface_driver) return loaded_class(conf) except ImportError: LOG.error("Error loading interface driver '%s'", conf.interface_driver) raise SystemExit(1)
def load_metering_driver(plugin, conf): """Load metering driver :param plugin: the metering plugin :param conf: driver configuration object :raises SystemExit of 1 if driver cannot be loaded """ try: loaded_class = runtime.load_class_by_alias_or_classname( METERING_NAMESPACE, conf.driver) return loaded_class(plugin, conf) except ImportError: LOG.error("Error loading metering driver '%s'", conf.driver) raise SystemExit(1)
def load_interface_driver(conf, get_networks_callback=None): """Load interface driver for agents like DHCP or L3 agent. :param conf: Driver configuration object :param get_networks_callback: A callback to get network information. This will be passed as additional keyword argument to the interface driver. :raises SystemExit of 1 if driver cannot be loaded """ try: loaded_class = runtime.load_class_by_alias_or_classname( INTERFACE_NAMESPACE, conf.interface_driver) return loaded_class(conf, get_networks_callback=get_networks_callback) except ImportError: LOG.error("Error loading interface driver '%s'", conf.interface_driver) raise SystemExit(1)
def __init__(self, conf, plugin_rpc, process_monitor): super(HaproxyNSDriver, self).__init__(conf, plugin_rpc, process_monitor) self.state_path = conf.haproxy.loadbalancer_state_path self.state_path = os.path.join( self.conf.haproxy.loadbalancer_state_path, STATE_PATH_V2_APPEND) try: vif_driver_class = runtime.load_class_by_alias_or_classname( 'neutron.interface_drivers', conf.interface_driver) except ImportError: with excutils.save_and_reraise_exception(): msg = (_('Error importing interface driver: %s') % conf.interface_driver) LOG.error(msg) self.vif_driver = vif_driver_class(conf) self.deployed_loadbalancers = {} self._loadbalancer = LoadBalancerManager(self) self._listener = ListenerManager(self) self._pool = PoolManager(self) self._member = MemberManager(self) self._healthmonitor = HealthMonitorManager(self)
def __init__(self, conf, plugin_rpc, process_monitor): super(HaproxyNSDriver, self).__init__(conf, plugin_rpc, process_monitor) self.state_path = conf.haproxy.loadbalancer_state_path self.state_path = os.path.join( self.conf.haproxy.loadbalancer_state_path, STATE_PATH_V2_APPEND) try: vif_driver_class = runtime.load_class_by_alias_or_classname( 'neutron.interface_drivers', conf.interface_driver) except ImportError: with excutils.save_and_reraise_exception(): msg = (_('Error importing interface driver: %s') % conf.interface_driver) LOG.error(msg) self.vif_driver = vif_driver_class(conf) self.deployed_loadbalancers = {} self._loadbalancer = LoadBalancerManager(self) self._listener = ListenerManager(self) self._pool = PoolManager(self) self._member = MemberManager(self) self._healthmonitor = HealthMonitorManager(self)
def load_firewall_driver_class(driver): return runtime.load_class_by_alias_or_classname( 'neutron.agent.firewall_drivers', driver)
def test_load_class_by_alias_or_classname_with_classname( self, mock_log, mock_import): self.assertEqual( mock.sentinel.dummy_class, runtime.load_class_by_alias_or_classname('ns', 'n'))
def test_load_class_by_alias_or_classname_dummy_driver( self, mock_log, mock_driver): self.assertEqual(_DummyDriver.driver, runtime.load_class_by_alias_or_classname('ns', 'n'))
def load_firewall_driver_class(driver): return runtime.load_class_by_alias_or_classname( 'neutron.agent.firewall_drivers', driver)