本文整理匯總了Python中oslo_utils.importutils.import_class方法的典型用法代碼示例。如果您正苦於以下問題:Python importutils.import_class方法的具體用法?Python importutils.import_class怎麽用?Python importutils.import_class使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oslo_utils.importutils
的用法示例。
在下文中一共展示了importutils.import_class方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_matching_classes
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def get_matching_classes(self, loadable_class_names):
"""Get loadable classes from a list of names.
Each name can be a full module path or the full path to a
method that returns classes to use. The latter behavior
is useful to specify a method that returns a list of
classes to use in a default case.
"""
classes = []
for cls_name in loadable_class_names:
obj = importutils.import_class(cls_name)
if self._is_correct_class(obj):
classes.append(obj)
elif inspect.isfunction(obj):
# Get list of classes from a function
for cls in obj():
classes.append(cls)
else:
error_str = 'Not a class of the correct type'
raise exception.ClassNotFound(class_name=cls_name,
exception=error_str)
return classes
示例2: _get_manager
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def _get_manager(self):
"""Initialize a Manager object appropriate for this service.
Use the service name to look up a Manager subclass from the
configuration and initialize an instance. If no class name
is configured, just return None.
:returns: a Manager instance, or None.
"""
fl = '%s_manager' % self.name
if fl not in CONF:
return None
manager_class_name = CONF.get(fl, None)
if not manager_class_name:
return None
manager_class = importutils.import_class(manager_class_name)
return manager_class()
示例3: API
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def API(configuration=None):
conf = configuration or cfg.CONF
conf.register_opts(key_manager_opts, group='key_manager')
try:
mgr = driver.DriverManager("castellan.drivers",
conf.key_manager.backend,
invoke_on_load=True,
invoke_args=[conf])
key_mgr = mgr.driver
except exception.NoMatches:
LOG.warning("Deprecation Warning : %s is not a stevedore based driver,"
" trying to load it as a class", conf.key_manager.backend)
cls = importutils.import_class(conf.key_manager.backend)
key_mgr = cls(configuration=conf)
return migration.handle_migration(conf, key_mgr)
示例4: get_client_class
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def get_client_class(api_name, version, version_map):
"""Returns the client class for the requested API version.
:param api_name: the name of the API, e.g. 'compute', 'image', etc
:param version: the requested API version
:param version_map: a dict of client classes keyed by version
:rtype: a client class for the requested API version
"""
try:
client_path = version_map[str(version)]
except (KeyError, ValueError):
msg = _("Invalid %(api_name)s client version '%(version)s'. must be "
"one of: %(map_keys)s")
msg = msg % {'api_name': api_name, 'version': version,
'map_keys': ', '.join(version_map.keys())}
raise exceptions.UnsupportedVersion(msg)
return importutils.import_class(client_path)
示例5: get_class
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def get_class(api_name, version, version_map):
"""Returns the client class for the requested API version
:param api_name: the name of the API, e.g. 'compute', 'image', etc
:param version: the requested API version
:param version_map: a dict of client classes keyed by version
:rtype: a client class for the requested API version
"""
try:
client_path = version_map[str(version)]
except (KeyError, ValueError):
msg = _("Invalid %(api_name)s client version '%(version)s'. "
"Must be one of: %(version_map)s") % {
'api_name': api_name,
'version': version,
'version_map': ', '.join(version_map.keys())}
raise exceptions.UnsupportedVersion(msg)
return importutils.import_class(client_path)
示例6: load_extension
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def load_extension(self, ext_factory):
"""Execute an extension factory.
Loads an extension. The 'ext_factory' is the name of a
callable that will be imported and called with one
argument--the extension manager. The factory callable is
expected to call the register() method at least once.
"""
LOG.debug("Loading extension %s", ext_factory)
# Load the factory
factory = importutils.import_class(ext_factory)
# Call it
LOG.debug("Calling extension factory %s", ext_factory)
factory(self)
示例7: __init__
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def __init__(self, host, binary, topic, manager, report_interval=None,
periodic_interval=None, periodic_fuzzy_delay=None,
service_name=None, coordination=False, *args, **kwargs):
super(Service, self).__init__()
if not rpc.initialized():
rpc.init(CONF)
self.host = host
self.binary = binary
self.topic = topic
self.manager_class_name = manager
manager_class = importutils.import_class(self.manager_class_name)
self.manager = manager_class(host=self.host,
service_name=service_name,
*args, **kwargs)
self.availability_zone = self.manager.availability_zone
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 = []
self.coordinator = coordination
示例8: load_extension
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def load_extension(self, ext_factory):
"""Execute an extension factory.
Loads an extension. The 'ext_factory' is the name of a
callable that will be imported and called with one
argument--the extension manager. The factory callable is
expected to call the register() method at least once.
"""
LOG.debug("Loading extension %s", ext_factory)
if isinstance(ext_factory, six.string_types):
# Load the factory
factory = importutils.import_class(ext_factory)
else:
factory = ext_factory
# Call it
LOG.debug("Calling extension factory %s", ext_factory)
factory(self)
示例9: __init__
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def __init__(self, host, binary, topic, manager,
periodic_enable=None, periodic_fuzzy_delay=None,
periodic_interval_max=None):
super(Service, self).__init__()
if not rpc.initialized():
rpc.init(CONF)
self.host = host
self.binary = binary
self.topic = topic
self.manager_class_name = manager
manager_class = importutils.import_class(self.manager_class_name)
self.rpcserver = None
self.manager = manager_class(host=self.host)
self.periodic_enable = periodic_enable
self.periodic_fuzzy_delay = periodic_fuzzy_delay
self.periodic_interval_max = periodic_interval_max
示例10: load_driver
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def load_driver(driver_cfg, namespace, *args, **kwargs):
try:
# Try to resolve by alias
mgr = driver.DriverManager(namespace, driver_cfg)
class_to_load = mgr.driver
except RuntimeError:
e1_info = sys.exc_info()
# try with name
try:
class_to_load = importutils.import_class(driver_cfg)
except (ImportError, ValueError):
LOG.error("Error loading class %(class)s by alias e: %(e)s",
{'class': driver_cfg, 'e': e1_info},
exc_info=e1_info)
LOG.error("Error loading class by class name",
exc_info=True)
raise ImportError(_("Class not found."))
return class_to_load(*args, **kwargs)
示例11: all_generators
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def all_generators():
for mod_name in SUPPORTED_MODULES:
prefix = mod_name.replace(' ', '')
mod_namespace = mod_name.lower().replace(' ', '_')
mod_cls_name = 'mistral_extra.actions.openstack.actions.%sAction' \
% prefix
mod_action_cls = importutils.import_class(mod_cls_name)
generator_cls_name = '%sActionGenerator' % prefix
yield type(
generator_cls_name,
(base.OpenStackActionGenerator,),
{
'action_namespace': mod_namespace,
'base_action_class': mod_action_cls
}
)
示例12: get_matching_classes
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def get_matching_classes(self, loadable_class_names):
"""Get loadable classes from a list of names.
Each name can be a full module path or the full path to a method that
returns classes to use. The latter behavior is useful to specify a
method that returns a list of classes to use in a default case.
"""
classes = []
for cls_name in loadable_class_names:
obj = importutils.import_class(cls_name)
if self._is_correct_class(obj):
classes.append(obj)
elif inspect.isfunction(obj):
# Get list of classes from a function
for cls in obj():
classes.append(cls)
else:
error_str = 'Not a class of the correct type'
raise exception.ClassNotFound(class_name=cls_name,
exception=error_str)
return classes
示例13: setUp
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def setUp(self):
super(FileSystemBankPluginTest, self).setUp()
import_str = (
"karbor.services.protection.bank_plugins."
"file_system_bank_plugin.FileSystemBankPlugin"
)
plugin_config = cfg.ConfigOpts()
plugin_config_fixture = self.useFixture(fixture.Config(plugin_config))
plugin_config_fixture.load_raw_values(
group='file_system_bank_plugin',
file_system_bank_path=tempfile.mkdtemp(),
)
fs_bank_plugin_cls = importutils.import_class(
import_str=import_str)
self.fs_bank_plugin = fs_bank_plugin_cls(plugin_config)
示例14: __init__
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def __init__(self, host, binary, topic, manager, report_interval=None,
periodic_interval=None, periodic_fuzzy_delay=None,
service_name=None, *args, **kwargs):
super(Service, self).__init__()
rpc.init(CONF)
self.host = host
self.binary = binary
self.topic = topic
self.manager_class_name = manager
manager_class = importutils.import_class(self.manager_class_name)
self.manager = manager_class(host=self.host,
service_name=service_name,
*args, **kwargs)
self.report_interval = report_interval
self.periodic_interval = periodic_interval
self.periodic_fuzzy_delay = periodic_fuzzy_delay
self.basic_config_check()
self.saved_args, self.saved_kwargs = args, kwargs
self.timers = []
self.rpcserver = None
示例15: get_client_class
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_class [as 別名]
def get_client_class(api_name, version, version_map):
"""Returns the client class for the requested API version.
:param api_name: the name of the API, e.g. 'compute', 'image', etc
:param version: the requested API version
:param version_map: a dict of client classes keyed by version
:rtype: a client class for the requested API version
"""
try:
client_path = version_map[str(version)]
except (KeyError, ValueError):
msg = _("Invalid %(api_name)s client version '%(version)s'. must be "
"one of: %(map_keys)s")
msg = msg % {'api_name': api_name, 'version': version,
'map_keys': ', '.join(version_map.keys())}
raise exceptions.UnsupportedVersion(message=msg)
return importutils.import_class(client_path)