当前位置: 首页>>代码示例>>Python>>正文


Python importutils.try_import方法代码示例

本文整理汇总了Python中oslo_utils.importutils.try_import方法的典型用法代码示例。如果您正苦于以下问题:Python importutils.try_import方法的具体用法?Python importutils.try_import怎么用?Python importutils.try_import使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_utils.importutils的用法示例。


在下文中一共展示了importutils.try_import方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: stop

# 需要导入模块: from oslo_utils import importutils [as 别名]
# 或者: from oslo_utils.importutils import try_import [as 别名]
def stop(self):
        LOG.info('Stopping service %s (%s)', self.svc_name, id(self.svc))

        try:
            self.svc.stop()

        except Exception:
            LOG.error('Failed to stop service %s (%s)',
                      self.svc_name, id(self.svc))
            raise

        finally:
            # Always try reset the service's RPCAPI
            mod = importutils.try_import('designate.%s.rpcapi' % self.svc_name)
            if hasattr(mod, 'reset'):
                LOG.info('Resetting service %s RPCAPI', self.svc_name)
                mod.reset() 
开发者ID:openstack,项目名称:designate,代码行数:19,代码来源:fixtures.py

示例2: _try_import

# 需要导入模块: from oslo_utils import importutils [as 别名]
# 或者: from oslo_utils.importutils import try_import [as 别名]
def _try_import(module_name):
    try:
        return importutils.try_import(module_name)
    except Exception as e:
        msg = 'Unable to load module "%s". %s' % (module_name, str(e))
        LOG.error(msg)
        return None 
开发者ID:openstack,项目名称:mistral-extra,代码行数:9,代码来源:actions.py

示例3: __init__

# 需要导入模块: from oslo_utils import importutils [as 别名]
# 或者: from oslo_utils.importutils import try_import [as 别名]
def __init__(self, manager_module, manager_class, topic, host=None):
        super(RPCService, self).__init__()
        self.topic = topic
        self.host = host or CONF.host
        manager_module = importutils.try_import(manager_module)
        manager_class = getattr(manager_module, manager_class)
        self.manager = manager_class(self.topic, self.host)
        self.rpcserver = None 
开发者ID:openstack,项目名称:cyborg,代码行数:10,代码来源:service.py

示例4: test_try_import

# 需要导入模块: from oslo_utils import importutils [as 别名]
# 或者: from oslo_utils.importutils import try_import [as 别名]
def test_try_import(self):
        dt = importutils.try_import('datetime')
        self.assertEqual(sys.modules['datetime'], dt) 
开发者ID:openstack,项目名称:oslo.utils,代码行数:5,代码来源:test_importutils.py

示例5: test_try_import_returns_default

# 需要导入模块: from oslo_utils import importutils [as 别名]
# 或者: from oslo_utils.importutils import try_import [as 别名]
def test_try_import_returns_default(self):
        foo = importutils.try_import('foo.bar')
        self.assertIsNone(foo) 
开发者ID:openstack,项目名称:oslo.utils,代码行数:5,代码来源:test_importutils.py

示例6: __init__

# 需要导入模块: from oslo_utils import importutils [as 别名]
# 或者: from oslo_utils.importutils import try_import [as 别名]
def __init__(self, connection_str, project=None, service=None, host=None,
                 context=None, conf=None, transport_url=None,
                 idle_timeout=1, **kwargs):
        """Driver that uses messaging as transport for notifications

        :param connection_str: OSProfiler driver connection string,
               equals to messaging://
        :param project: project name that will be included into notification
        :param service: service name that will be included into notification
        :param host: host name that will be included into notification
        :param context: oslo.messaging context
        :param conf: oslo.config CONF object
        :param transport_url: oslo.messaging transport, e.g.
               rabbit://rabbit:password@devstack:5672/
        :param idle_timeout: how long to wait for new notifications after
               the last one seen in the trace; this parameter is useful to
               collect full trace of asynchronous commands, e.g. when user
               runs `osprofiler` right after `openstack server create`
        :param kwargs: black hole for any other parameters
        """

        self.oslo_messaging = importutils.try_import("oslo_messaging")
        if not self.oslo_messaging:
            raise ValueError("Oslo.messaging library is required for "
                             "messaging driver")

        super(Messaging, self).__init__(connection_str, project=project,
                                        service=service, host=host)

        self.context = context

        if not conf:
            oslo_config = importutils.try_import("oslo_config")
            if not oslo_config:
                raise ValueError("Oslo.config library is required for "
                                 "messaging driver")
            conf = oslo_config.cfg.CONF

        transport_kwargs = {}
        if transport_url:
            transport_kwargs["url"] = transport_url

        self.transport = self.oslo_messaging.get_notification_transport(
            conf, **transport_kwargs)
        self.client = self.oslo_messaging.Notifier(
            self.transport, publisher_id=self.host, driver="messaging",
            topics=["profiler"], retry=0)

        self.idle_timeout = idle_timeout 
开发者ID:openstack,项目名称:osprofiler,代码行数:51,代码来源:messaging.py


注:本文中的oslo_utils.importutils.try_import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。