本文整理匯總了Python中oslo_utils.importutils.import_module方法的典型用法代碼示例。如果您正苦於以下問題:Python importutils.import_module方法的具體用法?Python importutils.import_module怎麽用?Python importutils.import_module使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oslo_utils.importutils
的用法示例。
在下文中一共展示了importutils.import_module方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_conf_modules
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def load_conf_modules():
"""Loads all modules that contain configuration.
Method iterates over modules of :py:module:`monasca_api.conf`
and imports only those that contain following methods:
- list_opts (required by oslo_config.genconfig)
- register_opts (required by :py:currentmodule:)
"""
for modname in _list_module_names():
mod = importutils.import_module('monasca_api.conf.' + modname)
required_funcs = ['register_opts', 'list_opts']
for func in required_funcs:
if hasattr(mod, func):
yield mod
示例2: make_plugin_base_section
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def make_plugin_base_section(plugin_group):
elements = []
for item in plugin_group["items"]:
name = item["name"].title() if "SLA" != item["name"] else item["name"]
category_obj = category("%s %ss" % (plugin_group["group"].title(),
name))
elements.append(category_obj)
module, cls = item["base"].split(":")
plugin_base = getattr(importutils.import_module(module), cls)
for p in plugin_base.get_all():
category_obj.append(make_plugin_section(p, item["name"]))
return elements
示例3: load_conf_modules
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def load_conf_modules():
"""Loads all modules that contain configuration
Method iterates over modules of :py:module:`monasca_log_api.conf`
and imports only those that contain following methods:
- list_opts (required by oslo_config.genconfig)
- register_opts (required by :py:currentmodule:)
"""
for modname in _list_module_names():
mod = importutils.import_module('monasca_log_api.conf.' + modname)
required_funcs = ['register_opts', 'list_opts']
for func in required_funcs:
if hasattr(mod, func):
yield mod
示例4: port_unbind
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def port_unbind(endpoint_id, neutron_port, driver=None, **kwargs):
"""Unbinds the Neutron port from the network interface on the host.
:param endpoint_id: the ID of the Docker container as string
:param neutron_port: a port dictionary returned from python-neutronclient
:param driver: the binding driver name
:param kwargs: Additional driver-specific arguments
:returns: the tuple of stdout and stderr returned by processutils.execute
invoked with the executable script for unbinding
:raises: processutils.ProcessExecutionError, pyroute2.NetlinkError,
kuryr.common.exceptions.DriverNotEnabledException,
"""
driver = importutils.import_module(
driver or cfg.CONF.binding.default_driver)
_verify_driver(driver)
return driver.port_unbind(endpoint_id, neutron_port, **kwargs)
示例5: test_all_public_methods_are_traced
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def test_all_public_methods_are_traced(self):
profiler_opts.set_defaults(conf.CONF)
self.config(enabled=True,
group='profiler')
classes = [
'zun.compute.api.API',
'zun.compute.rpcapi.API',
]
for clsname in classes:
# give the metaclass and trace_cls() decorator a chance to patch
# methods of the classes above
imp.reload(
importutils.import_module(clsname.rsplit('.', 1)[0]))
cls = importutils.import_class(clsname)
for attr, obj in cls.__dict__.items():
# only public methods are traced
if attr.startswith('_'):
continue
# only checks callables
if not (inspect.ismethod(obj) or inspect.isfunction(obj)):
continue
# osprofiler skips static methods
if isinstance(obj, staticmethod):
continue
self.assertTrue(getattr(obj, '__traced__', False), obj)
示例6: _get_classes_from_module
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def _get_classes_from_module(self, module_name):
"""Get the classes from a module that match the type we want."""
classes = []
module = importutils.import_module(module_name)
for obj_name in dir(module):
# Skip objects that are meant to be private.
if obj_name.startswith('_'):
continue
itm = getattr(module, obj_name)
if self._is_correct_class(itm):
classes.append(itm)
return classes
示例7: import_versioned_module
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def import_versioned_module(version, submodule=None):
module = 'monitoringclient.v%s' % version
if submodule:
module = '.'.join((module, submodule))
return importutils.import_module(module)
示例8: import_versioned_module
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def import_versioned_module(version, submodule=None):
module = 'heatclient.v%s' % version
if submodule:
module = '.'.join((module, submodule))
return importutils.import_module(module)
示例9: get_version_info
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def get_version_info(self, stack):
stack_param = self.template_def.get_heat_param(
cluster_attr='coe_version')
if stack_param:
self.cluster.coe_version = stack.parameters[stack_param]
version_module_path = self.template_def.driver_module_path+'.version'
try:
ver = importutils.import_module(version_module_path)
container_version = ver.container_version
except Exception:
container_version = None
self.cluster.container_version = container_version
示例10: test_all_public_methods_are_traced
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def test_all_public_methods_are_traced(self):
profiler_opts.set_defaults(conf.CONF)
self.config(enabled=True,
group='profiler')
classes = [
'magnum.conductor.api.API',
'magnum.conductor.api.ListenerAPI',
'magnum.conductor.handlers.ca_conductor.Handler',
'magnum.conductor.handlers.cluster_conductor.Handler',
'magnum.conductor.handlers.conductor_listener.Handler',
'magnum.conductor.handlers.indirection_api.Handler',
'magnum.service.periodic.MagnumPeriodicTasks',
]
for clsname in classes:
# give the metaclass and trace_cls() decorator a chance to patch
# methods of the classes above
six.reload_module(
importutils.import_module(clsname.rsplit('.', 1)[0]))
cls = importutils.import_class(clsname)
for attr, obj in cls.__dict__.items():
# only public methods are traced
if attr.startswith('_'):
continue
# only checks callables
if not (inspect.ismethod(obj) or inspect.isfunction(obj)):
continue
# osprofiler skips static methods
if isinstance(obj, staticmethod):
continue
self.assertTrue(getattr(obj, '__traced__', False), obj)
示例11: add_policy_attributes
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def add_policy_attributes(target):
"""Adds extra information for policy enforcement to raw target object"""
context = importutils.import_module('magnum.common.context')
admin_context = context.make_admin_context()
admin_osc = clients.OpenStackClients(admin_context)
trustee_domain_id = admin_osc.keystone().trustee_domain_id
target['trustee_domain_id'] = trustee_domain_id
return target
示例12: setup_rados
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def setup_rados():
global rados
if not rados:
try:
rados = importutils.import_module('rados')
except ImportError:
raise exception.ShareBackendException(
_("python-rados is not installed"))
示例13: setup_winrm
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def setup_winrm():
global winrm
if not winrm:
try:
winrm = importutils.import_module('winrm')
except ImportError:
raise exception.ShareBackendException(
_("PyWinrm is not installed"))
示例14: __init__
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def __init__(self, db_driver=None):
super(Base, self).__init__()
if not db_driver:
db_driver = CONF.db_driver
self.db = importutils.import_module(db_driver) # pylint: disable=C0103
示例15: datasources_opts
# 需要導入模塊: from oslo_utils import importutils [as 別名]
# 或者: from oslo_utils.importutils import import_module [as 別名]
def datasources_opts():
top = os.getcwd()
datasources = _normalize_path_to_datasource_name(
_filter_folders_containing_transformer(_get_datasources_folders(top)),
top)
return [(datasource, module.OPTS) for datasource in datasources
for module in
[importutils.import_module(DATASOURCES_PATH + datasource)]
if 'OPTS' in vars(module)]