當前位置: 首頁>>代碼示例>>Python>>正文


Python context.get_current方法代碼示例

本文整理匯總了Python中oslo_context.context.get_current方法的典型用法代碼示例。如果您正苦於以下問題:Python context.get_current方法的具體用法?Python context.get_current怎麽用?Python context.get_current使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oslo_context.context的用法示例。


在下文中一共展示了context.get_current方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: spawn_n

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def spawn_n(func, *args, **kwargs):
    """Passthrough method for eventlet.spawn_n.

    This utility exists so that it can be stubbed for testing without
    interfering with the service spawns.

    It will also grab the context from the threadlocal store and add it to
    the store on the new thread.  This allows for continuity in logging the
    context when using this method to spawn a new thread.
    """
    _context = common_context.get_current()

    @functools.wraps(func)
    def context_wrapper(*args, **kwargs):
        # NOTE: If update_store is not called after spawn_n it won't be
        # available for the logger to pull from threadlocal storage.
        if _context is not None:
            _context.update_store()
        func(*args, **kwargs)

    eventlet.spawn_n(context_wrapper, *args, **kwargs) 
開發者ID:openstack,項目名稱:zun,代碼行數:23,代碼來源:utils.py

示例2: _update_record_with_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def _update_record_with_context(record):
    """Given a log record, update it with context information.

    The request context, if there is one, will either be passed with the
    incoming record or in the global thread-local store.
    """
    context = record.__dict__.get(
        'context',
        context_utils.get_current()
    )
    if context:
        d = _dictify_context(context)
        # Copy the context values directly onto the record so they can be
        # used by the formatting strings.
        for k, v in d.items():
            setattr(record, k, v)

    return context 
開發者ID:openstack,項目名稱:oslo.log,代碼行數:20,代碼來源:formatters.py

示例3: spawn

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def spawn(func, *args, **kwargs):
    """Passthrough method for eventlet.spawn.

    This utility exists so that it can be stubbed for testing without
    interfering with the service spawns.

    It will also grab the context from the threadlocal store and add it to
    the store on the new thread.  This allows for continuity in logging the
    context when using this method to spawn a new thread.
    """
    _context = common_context.get_current()

    @functools.wraps(func)
    def context_wrapper(*args, **kwargs):
        # NOTE: If update_store is not called after spawn it won't be
        # available for the logger to pull from threadlocal storage.
        if _context is not None:
            _context.update_store()
        return func(*args, **kwargs)

    return eventlet.spawn(context_wrapper, *args, **kwargs) 
開發者ID:openstack,項目名稱:masakari,代碼行數:23,代碼來源:utils.py

示例4: test_spawn_n_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def test_spawn_n_context(self):
        self.assertIsNone(common_context.get_current())
        ctxt = context.RequestContext('user', 'project')

        def _fake_spawn(func, *args, **kwargs):
            # call the method to ensure no error is raised
            func(*args, **kwargs)
            self.assertEqual(ctxt, args[0])
            self.assertEqual('test', kwargs['kwarg1'])

        def fake(context, kwarg1=None):
            pass

        with mock.patch.object(eventlet, self.spawn_name, _fake_spawn):
            getattr(utils, self.spawn_name)(fake, ctxt, kwarg1='test')
        self.assertEqual(ctxt, common_context.get_current()) 
開發者ID:openstack,項目名稱:masakari,代碼行數:18,代碼來源:test_utils.py

示例5: test_spawn_n_context_different_from_passed

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def test_spawn_n_context_different_from_passed(self):
        self.assertIsNone(common_context.get_current())
        ctxt = context.RequestContext('user', 'project')
        ctxt_passed = context.RequestContext('user', 'project',
                overwrite=False)
        self.assertEqual(ctxt, common_context.get_current())

        def _fake_spawn(func, *args, **kwargs):
            # call the method to ensure no error is raised
            func(*args, **kwargs)
            self.assertEqual(ctxt_passed, args[0])
            self.assertEqual('test', kwargs['kwarg1'])

        def fake(context, kwarg1=None):
            pass

        with mock.patch.object(eventlet, self.spawn_name, _fake_spawn):
            getattr(utils, self.spawn_name)(fake, ctxt_passed, kwarg1='test')
        self.assertEqual(ctxt, common_context.get_current()) 
開發者ID:openstack,項目名稱:masakari,代碼行數:21,代碼來源:test_utils.py

示例6: test_tacker_context_overwrite

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def test_tacker_context_overwrite(self):
        ctx1 = context.Context('user_id', 'tenant_id')
        self.assertEqual(oslo_context.get_current().request_id,
                         ctx1.request_id)

        # If overwrite is not specified, request_id should be updated.
        ctx2 = context.Context('user_id', 'tenant_id')
        self.assertNotEqual(ctx2.request_id, ctx1.request_id)
        self.assertEqual(oslo_context.get_current().request_id,
                         ctx2.request_id)

        # If overwrite is specified, request_id should be kept.
        ctx3 = context.Context('user_id', 'tenant_id', overwrite=False)
        self.assertNotEqual(ctx3.request_id, ctx2.request_id)
        self.assertEqual(oslo_context.get_current().request_id,
                         ctx2.request_id) 
開發者ID:openstack,項目名稱:tacker,代碼行數:18,代碼來源:test_context.py

示例7: _build_conn_params

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def _build_conn_params(self, user, project):
        """Build connection params for specific user and project.

        :param user: The ID of the user for which a trust will be used.
        :param project: The ID of the project for which a trust will be used.
        :returns: A dict containing the required parameters for connection
                  creation.
        """
        service_creds = senlin_context.get_service_credentials()
        params = {
            'username': service_creds.get('username'),
            'password': service_creds.get('password'),
            'auth_url': service_creds.get('auth_url'),
            'user_domain_name': service_creds.get('user_domain_name')
        }

        cred = co.Credential.get(oslo_context.get_current(), user, project)
        if cred is None:
            raise exception.TrustNotFound(trustor=user)
        params['trust_id'] = cred.cred['openstack']['trust']

        return params 
開發者ID:openstack,項目名稱:senlin,代碼行數:24,代碼來源:message.py

示例8: _build_conn_params

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def _build_conn_params(self, user, project):
        """Build connection params for specific user and project.

        :param user: The ID of the user for which a trust will be used.
        :param project: The ID of the project for which a trust will be used.
        :returns: A dict containing the required parameters for connection
                  creation.
        """
        cred = co.Credential.get(oslo_context.get_current(), user, project)
        if cred is None:
            raise exc.TrustNotFound(trustor=user)

        trust_id = cred.cred['openstack']['trust']

        # This is supposed to be trust-based authentication
        params = copy.deepcopy(self.context)
        params['trust_id'] = trust_id

        return params 
開發者ID:openstack,項目名稱:senlin,代碼行數:21,代碼來源:base.py

示例9: test_start_action_no_action_id

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def test_start_action_no_action_id(self, mock_acquire_action):
        mock_action = mock.Mock()
        mock_action.id = '0123'
        mock_action.action = 'CLUSTER_CREATE'
        mock_acquire_action.side_effect = [mock_action, None]

        svc = service.EngineService('HOST', 'TOPIC')
        svc.tg = self.mock_tg
        svc.start_action('4567')

        self.mock_tg.add_thread.assert_called_once_with(
            svc._start_with_trace,
            oslo_context.get_current(),
            None, actionm.ActionProc,
            svc.db_session, '0123'
        ) 
開發者ID:openstack,項目名稱:senlin,代碼行數:18,代碼來源:test_service.py

示例10: _build_conn_params

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def _build_conn_params(self, user, project):
        """Build trust-based connection parameters.

        :param user: the user for which the trust will be checked.
        :param project: the user for which the trust will be checked.
        """
        service_creds = senlin_context.get_service_credentials()
        params = {
            'username': service_creds.get('username'),
            'password': service_creds.get('password'),
            'auth_url': service_creds.get('auth_url'),
            'user_domain_name': service_creds.get('user_domain_name')
        }

        cred = co.Credential.get(oslo_context.get_current(), user, project)
        if cred is None:
            raise exception.TrustNotFound(trustor=user)
        params['trust_id'] = cred.cred['openstack']['trust']

        return params 
開發者ID:openstack,項目名稱:senlin,代碼行數:22,代碼來源:base.py

示例11: wait_for_task

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def wait_for_task(self, task):
        """Waits for the given task to complete and returns the result.

        The task is polled until it is done. The method returns the task
        information upon successful completion. In case of any error,
        appropriate exception is raised.

        :param task: managed object reference of the task
        :returns: task info upon successful completion of the task
        :raises: VimException, VimFaultException, VimAttributeException,
                 VimSessionOverLoadException, VimConnectionException
        """
        ctx = context.get_current()
        loop = loopingcall.FixedIntervalLoopingCall(self._poll_task, task, ctx)
        evt = loop.start(self._task_poll_interval)
        LOG.debug("Waiting for the task: %s to complete.", task)
        return evt.wait() 
開發者ID:openstack,項目名稱:oslo.vmware,代碼行數:19,代碼來源:api.py

示例12: test_neutron_context_overwrite

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def test_neutron_context_overwrite(self):
        ctx1 = context.Context('user_id', 'tenant_id')
        self.assertEqual(ctx1.request_id,
                         oslo_context.get_current().request_id)

        # If overwrite is not specified, request_id should be updated.
        ctx2 = context.Context('user_id', 'tenant_id')
        self.assertNotEqual(ctx2.request_id, ctx1.request_id)
        self.assertEqual(ctx2.request_id,
                         oslo_context.get_current().request_id)

        # If overwrite is specified, request_id should be kept.
        ctx3 = context.Context('user_id', 'tenant_id', overwrite=False)
        self.assertNotEqual(ctx3.request_id, ctx2.request_id)
        self.assertEqual(ctx2.request_id,
                         oslo_context.get_current().request_id) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:18,代碼來源:test_context.py

示例13: test_get_os_admin_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def test_get_os_admin_context(self, session, auth):
        conf = config_fixture.Config()
        clients._admin_session = None
        conf.config(auth_type='fake', group=GROUP_AUTHTOKEN)

        imp.reload(ec2_context)
        # NOTE(ft): initialize a regular context to populate oslo_context's
        # local storage to prevent admin context to populate it.
        # Used to implicitly validate overwrite=False argument of the call
        # RequestContext constructor from inside get_os_admin_context
        if not context.get_current():
            ec2_context.RequestContext(None, None)

        ctx = ec2_context.get_os_admin_context()
        conf = cfg.CONF
        auth.assert_called_once_with(conf, GROUP_AUTHTOKEN)
        auth_plugin = auth.return_value
        session.assert_called_once_with(conf, GROUP_AUTHTOKEN,
                                        auth=auth_plugin)
        self.assertIsNone(ctx.user_id)
        self.assertIsNone(ctx.project_id)
        self.assertIsNone(ctx.auth_token)
        self.assertEqual([], ctx.service_catalog)
        self.assertTrue(ctx.is_os_admin)
        self.assertIsNotNone(ctx.session)
        self.assertIsNotNone(ctx.session.auth)
        self.assertNotEqual(context.get_current(), ctx)

        session.reset_mock()
        ec2_context.get_os_admin_context()
        self.assertFalse(session.called) 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:33,代碼來源:test_context.py

示例14: get_current

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def get_current():
    return context.get_current() 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:4,代碼來源:context.py

示例15: __init__

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import get_current [as 別名]
def __init__(self, *args, **kwargs):
        # Store the caller's context as a private variable shared among threads
        self.__context__ = context_utils.get_current()
        super(Thread, self).__init__(*args, **kwargs) 
開發者ID:openstack,項目名稱:os-brick,代碼行數:6,代碼來源:executor.py


注:本文中的oslo_context.context.get_current方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。