Python oslo_utils.importutils.import_object() Examples
The following are 30
code examples of oslo_utils.importutils.import_object().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_utils.importutils
, or try the search function
.
Example #1
Source File: manager.py From manila with Apache License 2.0 | 6 votes |
def __init__(self, scheduler_driver=None, service_name=None, *args, **kwargs): if not scheduler_driver: scheduler_driver = CONF.scheduler_driver if scheduler_driver in MAPPING: msg_args = { 'old': scheduler_driver, 'new': MAPPING[scheduler_driver], } LOG.warning("Scheduler driver path %(old)s is deprecated, " "update your configuration to the new path " "%(new)s", msg_args) scheduler_driver = MAPPING[scheduler_driver] self.driver = importutils.import_object(scheduler_driver) self.message_api = message_api.API() super(SchedulerManager, self).__init__(*args, **kwargs)
Example #2
Source File: action_executor.py From vitrage with Apache License 2.0 | 6 votes |
def _register_action_recipes(): # noinspection PyDictCreation recipes = {} recipes[ActionType.SET_STATE] = importutils.import_object( "%s.%s" % (SetState.__module__, SetState.__name__)) recipes[ActionType.RAISE_ALARM] = importutils.import_object( "%s.%s" % (RaiseAlarm.__module__, RaiseAlarm.__name__)) recipes[ActionType.ADD_CAUSAL_RELATIONSHIP] = \ importutils.import_object( "%s.%s" % (AddCausalRelationship.__module__, AddCausalRelationship.__name__)) recipes[ActionType.MARK_DOWN] = importutils.import_object( "%s.%s" % (MarkDown.__module__, MarkDown.__name__)) recipes[ActionType.EXECUTE_MISTRAL] = importutils.import_object( "%s.%s" % (ExecuteMistral.__module__, ExecuteMistral.__name__)) return recipes
Example #3
Source File: utilsfactory.py From os-win with Apache License 2.0 | 6 votes |
def _get_class(class_type, *args, **kwargs): if class_type not in utils_map: raise exceptions.HyperVException(_('Class type %s does ' 'not exist') % class_type) windows_version = utils.get_windows_version() build = list(map(int, windows_version.split('.'))) windows_version = float("%i.%i" % (build[0], build[1])) existing_classes = utils_map.get(class_type, []) for class_variant in existing_classes: min_version = class_variant.get('min_version', DEFAULT_MIN_VERSION) max_version = class_variant.get('max_version', DEFAULT_MAX_VERSION) class_path = class_variant['path'] if (min_version <= windows_version and (max_version is None or windows_version < max_version)): return importutils.import_object(class_path, *args, **kwargs) raise exceptions.HyperVException(_('Could not find any %(class)s class for' 'this Windows version: %(win_version)s') % {'class': class_type, 'win_version': windows_version})
Example #4
Source File: driver.py From vitrage with Apache License 2.0 | 6 votes |
def zabbix_client_login(self): if not CONF.zabbix.user: LOG.warning('Zabbix user is not defined') if not CONF.zabbix.password: LOG.warning('Zabbix password is not defined') if not CONF.zabbix.url: LOG.warning('Zabbix url is not defined') try: if not self._client: self._client = utils.import_object( 'pyzabbix.ZabbixAPI', CONF.zabbix.url) self._client.login( CONF.zabbix.user, CONF.zabbix.password) except Exception: LOG.exception('pyzabbix.ZabbixAPI error occurred.') self._client = None
Example #5
Source File: vif.py From nova-powervm with Apache License 2.0 | 6 votes |
def _build_vif_driver(adapter, host_uuid, instance, vif): """Returns the appropriate VIF Driver for the given VIF. :param adapter: The pypowervm adapter API interface. :param host_uuid: The host system UUID. :param instance: The nova instance. :param vif: The virtual interface to from Nova. :return: The appropriate PvmVifDriver for the VIF. """ if vif.get('type') is None: raise exception.VirtualInterfacePlugException( _("vif_type parameter must be present for this vif_driver " "implementation")) # Check the type to the implementations if VIF_MAPPING.get(vif['type']): return importutils.import_object( VIF_MAPPING.get(vif['type']), adapter, host_uuid, instance) # No matching implementation, raise error. raise exception.VirtualInterfacePlugException( _("Unable to find appropriate PowerVM VIF Driver for VIF type " "%(vif_type)s on instance %(instance)s") % {'vif_type': vif['type'], 'instance': instance.name})
Example #6
Source File: rpc_l2gw.py From networking-l2gw with Apache License 2.0 | 6 votes |
def __init__(self, service_plugin, validator=None): super(L2gwRpcDriver, self).__init__(service_plugin, validator) self.ovsdb_callback = importutils.import_object( L2GW_CALLBACK, self) self.endpoints = ( [self.ovsdb_callback, agents_db.AgentExtRpcCallback()]) self.conn = n_rpc.Connection() self.conn.create_consumer(topics.L2GATEWAY_PLUGIN, self.endpoints, fanout=False) self.conn.consume_in_threads() self.create_rpc_conn() LOG.debug("starting l2gateway agent scheduler") self.start_l2gateway_agent_scheduler() self.gateway_resource = constants.GATEWAY_RESOURCE_NAME self.l2gateway_db = l2_gw_db.L2GatewayMixin() self.type_manager = managers.TypeManager() self.port_dict_before_update = []
Example #7
Source File: driver_v2.py From f5-openstack-lbaasv2-driver with Apache License 2.0 | 5 votes |
def __init__(self, plugin=None, env=None): """Driver initialization.""" if not plugin: LOG.error('Required LBaaS Driver and Core Driver Missing') sys.exit(1) self.plugin = plugin self.env = env self.loadbalancer = LoadBalancerManager(self) self.listener = ListenerManager(self) self.pool = PoolManager(self) self.member = MemberManager(self) self.healthmonitor = HealthMonitorManager(self) self.l7policy = L7PolicyManager(self) self.l7rule = L7RuleManager(self) self.unlegacy_setting_placeholder_driver_side = \ cfg.CONF.unlegacy_setting_placeholder_driver_side # what scheduler to use for pool selection self.scheduler = importutils.import_object( cfg.CONF.f5_loadbalancer_pool_scheduler_driver_v2) self.service_builder = importutils.import_object( cfg.CONF.f5_loadbalancer_service_builder_v2, self) self.agent_rpc = agent_rpc.LBaaSv2AgentRPC(self) self.plugin_rpc = plugin_rpc.LBaaSv2PluginCallbacksRPC(self) self.q_client = \ neutron_client.F5NetworksNeutronClient(self.plugin) # add this agent RPC to the neutron agent scheduler # mixins agent_notifiers dictionary for it's env self.plugin.agent_notifiers.update( {q_const.AGENT_TYPE_LOADBALANCER: self.agent_rpc}) registry.subscribe(self._bindRegistryCallback(), resources.PROCESS, events.AFTER_INIT)
Example #8
Source File: test_engine_mgr.py From masakari with Apache License 2.0 | 5 votes |
def setUp(self): super(EngineManagerUnitTestCase, self).setUp() rpc.init(CONF) self.engine = importutils.import_object(CONF.engine_manager) self.context = context.RequestContext()
Example #9
Source File: df_bgp_service.py From dragonflow with Apache License 2.0 | 5 votes |
def initialize_driver(self): try: self.bgp_driver = ( importutils.import_object(cfg.CONF.df_bgp.bgp_speaker_driver, cfg.CONF.df_bgp)) except ImportError: LOG.exception("Error while importing BGP speaker driver %s", cfg.CONF.df_bgp.bgp_speaker_driver) raise SystemExit(1)
Example #10
Source File: test_fc_driver.py From dragonflow with Apache License 2.0 | 5 votes |
def setUp(self): flowclassifier_plugin = ( test_flowclassifier_db.DB_FLOWCLASSIFIER_PLUGIN_CLASS) service_plugins = { flowclassifier.FLOW_CLASSIFIER_EXT: flowclassifier_plugin } fdb.FlowClassifierDbPlugin.supported_extension_aliases = [ flowclassifier.FLOW_CLASSIFIER_EXT] fdb.FlowClassifierDbPlugin.path_prefix = ( flowclassifier.FLOW_CLASSIFIER_PREFIX ) super(TestDfFcDriver, self).setUp( ext_mgr=None, plugin=None, service_plugins=service_plugins ) self.flowclassifier_plugin = importutils.import_object( flowclassifier_plugin) ext_mgr = api_ext.PluginAwareExtensionManager( test_flowclassifier_db.extensions_path, { flowclassifier.FLOW_CLASSIFIER_EXT: self.flowclassifier_plugin } ) app = config.load_paste_app('extensions_test_app') self.ext_api = api_ext.ExtensionMiddleware(app, ext_mgr=ext_mgr) self.ctx = context.get_admin_context() self.driver = driver.DfFlowClassifierDriver() self.driver.initialize() self.driver._nb_api = mock.Mock()
Example #11
Source File: l3_router_plugin.py From dragonflow with Apache License 2.0 | 5 votes |
def __init__(self): self.router_scheduler = importutils.import_object( cfg.CONF.router_scheduler_driver) super(DFL3AgentlessRouterPlugin, self).__init__() self._nb_api = None self._start_rpc_notifiers() self._register_callbacks()
Example #12
Source File: transformer_manager.py From vitrage with Apache License 2.0 | 5 votes |
def register_transformer_classes(): transformers = {} for datasource_type in CONF.datasources.types: try: transformers[datasource_type] = importutils.import_object( CONF[datasource_type].transformer, transformers) if opt_exists(CONF[datasource_type], ENTITIES): for entity in CONF[datasource_type].entities: transformers[entity] = importutils.import_object( CONF[datasource_type].transformer, transformers) except Exception: LOG.exception('Failed to register transformer %s.', datasource_type) transformers[VITRAGE_DATASOURCE] = importutils.import_object( "%s.%s" % (EvaluatorEventTransformer.__module__, EvaluatorEventTransformer.__name__), transformers) transformers[CONSISTENCY_DATASOURCE] = importutils.import_object( "%s.%s" % (ConsistencyTransformer.__module__, ConsistencyTransformer.__name__), transformers) return transformers
Example #13
Source File: utils.py From vitrage with Apache License 2.0 | 5 votes |
def get_drivers_by_name(driver_names): for d_name in driver_names: if not drivers.get(d_name): drivers[d_name] = utils.import_object(CONF[d_name].driver) drivers[d_name].__class__._datasource_name = d_name return [drivers[d_name] for d_name in driver_names]
Example #14
Source File: service.py From vitrage with Apache License 2.0 | 5 votes |
def get_notifier_plugins(): notifiers = [] conf_notifier_names = CONF.notifiers if not conf_notifier_names: LOG.info('There are no notifier plugins in configuration') return [] for notifier_name in conf_notifier_names: register_opts(notifier_name, CONF.notifiers_path) LOG.info('Notifier plugin %s started', notifier_name) notifiers.append(importutils.import_object( CONF[notifier_name].notifier)) return notifiers
Example #15
Source File: service.py From vitrage with Apache License 2.0 | 5 votes |
def get_machine_learning_plugins(): machine_learning_plugins = [] machine_learning_plugins_names = \ CONF.machine_learning.plugins if not machine_learning_plugins_names: LOG.info('There are no Machine Learning plugins in configuration') return [] for machine_learning_plugin_name in machine_learning_plugins_names: register_opts(machine_learning_plugin_name, CONF.machine_learning.plugins_path) LOG.info('Machine Learning plugin %s started', machine_learning_plugin_name) machine_learning_plugins.append(importutils.import_object( CONF[machine_learning_plugin_name].plugin_path)) return machine_learning_plugins
Example #16
Source File: quota.py From zun with Apache License 2.0 | 5 votes |
def _driver(self): if self.__driver: return self.__driver self.__driver = importutils.import_object(CONF.quota.driver) return self.__driver
Example #17
Source File: driver.py From nova-powervm with Apache License 2.0 | 5 votes |
def _setup_rebuild_store(self): """Set up the store for remote restart objects.""" store = CONF.powervm.nvram_store.lower() if store != 'none': self.store_api = importutils.import_object( NVRAM_NS + NVRAM_APIS[store]) # Events will be handled once the nvram_mgr is set. self.nvram_mgr = nvram_manager.NvramManager( self.store_api, self.adapter, self.host_uuid) # Do host startup for NVRAM for existing VMs on the host n_utils.spawn(self._nvram_host_startup)
Example #18
Source File: test_utilsfactory.py From os-win with Apache License 2.0 | 5 votes |
def test_utils_public_signatures(self): for module_name in utilsfactory.utils_map.keys(): classes = utilsfactory.utils_map[module_name] if len(classes) < 2: continue base_class_dict = classes[0] base_class = importutils.import_object(base_class_dict['path']) for i in range(1, len(classes)): tested_class_dict = classes[i] tested_class = importutils.import_object( tested_class_dict['path']) self.assertPublicAPISignatures(base_class, tested_class) self.assertPublicAPISignatures(tested_class, base_class)
Example #19
Source File: worker.py From karbor with Apache License 2.0 | 5 votes |
def _load_engine(self, engine_path): if not engine_path: engine_path = CONF.workflow_engine engine = importutils.import_object(engine_path) return engine
Example #20
Source File: quota.py From karbor with Apache License 2.0 | 5 votes |
def __init__(self, quota_driver_class=None): """Initialize a Quota object.""" if not quota_driver_class: quota_driver_class = CONF.quota_driver if isinstance(quota_driver_class, six.string_types): quota_driver_class = importutils.import_object(quota_driver_class) self._resources = {} self._driver = quota_driver_class
Example #21
Source File: test_importutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_import_object_optional_arg_not_present(self): obj = importutils.import_object('oslo_utils.tests.fake.FakeDriver') self.assertEqual(obj.__class__.__name__, 'FakeDriver')
Example #22
Source File: test_importutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_import_object_optional_arg_present(self): obj = importutils.import_object('oslo_utils.tests.fake.FakeDriver', first_arg=False) self.assertEqual(obj.__class__.__name__, 'FakeDriver')
Example #23
Source File: test_importutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_import_object_required_arg_not_present(self): # arg 1 isn't optional here self.assertRaises(TypeError, importutils.import_object, 'oslo_utils.tests.fake.FakeDriver2')
Example #24
Source File: test_importutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_import_object_required_arg_present(self): obj = importutils.import_object('oslo_utils.tests.fake.FakeDriver2', first_arg=False) self.assertEqual(obj.__class__.__name__, 'FakeDriver2') # namespace tests
Example #25
Source File: test_importutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_import_object(self): dt = importutils.import_object('datetime.time') self.assertIsInstance(dt, sys.modules['datetime'].time)
Example #26
Source File: mongo.py From oslo.cache with Apache License 2.0 | 5 votes |
def _assign_data_mainpulator(self): if self._data_manipulator is None: if self.son_manipulator: self._data_manipulator = importutils.import_object( self.son_manipulator) else: self._data_manipulator = BaseTransform()
Example #27
Source File: test_driver.py From networking-sfc with Apache License 2.0 | 5 votes |
def setUp(self): flowclassifier_plugin = ( test_flowclassifier_db.DB_FLOWCLASSIFIER_PLUGIN_CLASS) service_plugins = { flowclassifier.FLOW_CLASSIFIER_EXT: flowclassifier_plugin } fdb.FlowClassifierDbPlugin.supported_extension_aliases = [ flowclassifier.FLOW_CLASSIFIER_EXT] fdb.FlowClassifierDbPlugin.path_prefix = ( flowclassifier.FLOW_CLASSIFIER_PREFIX ) super(OVSFlowClassifierDriverTestCase, self).setUp( ext_mgr=None, plugin=None, service_plugins=service_plugins ) self.flowclassifier_plugin = importutils.import_object( flowclassifier_plugin) ext_mgr = api_ext.PluginAwareExtensionManager( test_flowclassifier_db.extensions_path, { flowclassifier.FLOW_CLASSIFIER_EXT: self.flowclassifier_plugin } ) app = config.load_paste_app('extensions_test_app') self.ext_api = api_ext.ExtensionMiddleware(app, ext_mgr=ext_mgr) self.ctx = context.get_admin_context() self.driver = driver.OVSFlowClassifierDriver() self.driver.initialize()
Example #28
Source File: test_sfc_db.py From networking-sfc with Apache License 2.0 | 5 votes |
def setUp(self, core_plugin=None, sfc_plugin=None, flowclassifier_plugin=None, ext_mgr=None): mock_log_p = mock.patch.object(sfc_db, 'LOG') self.mock_log = mock_log_p.start() cfg.CONF.register_opts(sfc.sfc_quota_opts, 'QUOTAS') if not sfc_plugin: sfc_plugin = DB_SFC_PLUGIN_CLASS if not flowclassifier_plugin: flowclassifier_plugin = ( test_flowclassifier_db.DB_FLOWCLASSIFIER_PLUGIN_CLASS) service_plugins = { sfc.SFC_EXT: sfc_plugin, fc_ext.FLOW_CLASSIFIER_EXT: flowclassifier_plugin } sfc_db.SfcDbPlugin.supported_extension_aliases = [ sfc.SFC_EXT, sg_ext.SG_EXT, tap_ext.TAP_EXT] sfc_db.SfcDbPlugin.path_prefix = sfc.SFC_PREFIX fdb.FlowClassifierDbPlugin.supported_extension_aliases = [ fc_ext.FLOW_CLASSIFIER_EXT] fdb.FlowClassifierDbPlugin.path_prefix = ( fc_ext.FLOW_CLASSIFIER_PREFIX ) super(SfcDbPluginTestCase, self).setUp( ext_mgr=ext_mgr, plugin=core_plugin, service_plugins=service_plugins ) if not ext_mgr: self.sfc_plugin = importutils.import_object(sfc_plugin) self.flowclassifier_plugin = importutils.import_object( flowclassifier_plugin) # Note (vks1): Auto-load extensions. ext_mgr = api_ext.PluginAwareExtensionManager.get_instance() app = config.load_paste_app('extensions_test_app') self.ext_api = api_ext.ExtensionMiddleware(app, ext_mgr=ext_mgr)
Example #29
Source File: test_flowclassifier_db.py From networking-sfc with Apache License 2.0 | 5 votes |
def setUp(self, core_plugin=None, flowclassifier_plugin=None, ext_mgr=None): mock_log_p = mock.patch.object(fdb, 'LOG') self.mock_log = mock_log_p.start() cfg.CONF.register_opts(fc_ext.flow_classifier_quota_opts, 'QUOTAS') if not flowclassifier_plugin: flowclassifier_plugin = DB_FLOWCLASSIFIER_PLUGIN_CLASS service_plugins = { fc_ext.FLOW_CLASSIFIER_EXT: flowclassifier_plugin } fdb.FlowClassifierDbPlugin.supported_extension_aliases = [ fc_ext.FLOW_CLASSIFIER_EXT] fdb.FlowClassifierDbPlugin.path_prefix = ( fc_ext.FLOW_CLASSIFIER_PREFIX ) super(FlowClassifierDbPluginTestCase, self).setUp( ext_mgr=ext_mgr, plugin=core_plugin, service_plugins=service_plugins ) if not ext_mgr: self.flowclassifier_plugin = importutils.import_object( flowclassifier_plugin) ext_mgr = api_ext.PluginAwareExtensionManager( extensions_path, {fc_ext.FLOW_CLASSIFIER_EXT: self.flowclassifier_plugin} ) app = config.load_paste_app('extensions_test_app') self.ext_api = api_ext.ExtensionMiddleware(app, ext_mgr=ext_mgr)
Example #30
Source File: common.py From freezer-api with Apache License 2.0 | 5 votes |
def get_db(driver=None): """Automatically loads the database driver to be used.""" storage = CONF.get('storage') if not driver: driver = storage['driver'] driver_instance = importutils.import_object( driver, backend=storage['backend'] ) return driver_instance