當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。