• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python context.set_ctx函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sahara.context.set_ctx函数的典型用法代码示例。如果您正苦于以下问题:Python set_ctx函数的具体用法?Python set_ctx怎么用?Python set_ctx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: handler

            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug("Rest.route.decorator.handler, kwargs={kwargs}".format(kwargs=kwargs))

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                kwargs.pop("tenant_id")
                ctx = context.Context(
                    flask.request.headers["X-User-Id"],
                    flask.request.headers["X-Tenant-Id"],
                    flask.request.headers["X-Auth-Token"],
                    flask.request.headers["X-Service-Catalog"],
                    flask.request.headers["X-User-Name"],
                    flask.request.headers["X-Tenant-Name"],
                    flask.request.headers["X-Roles"].split(","),
                )
                context.set_ctx(ctx)

                if flask.request.method in ["POST", "PUT"]:
                    kwargs["data"] = request_data()

                try:
                    return func(**kwargs)
                except ex.Forbidden as e:
                    return access_denied(e)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, "Internal Server Error", e)
开发者ID:YongchaoTIAN,项目名称:sahara,代码行数:34,代码来源:api.py


示例2: handler

            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug("Rest.route.decorator.handler, kwargs=%s", kwargs)

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                kwargs.pop("tenant_id")
                ctx = context.Context(
                    flask.request.headers['X-User-Id'],
                    flask.request.headers['X-Tenant-Id'],
                    flask.request.headers['X-Auth-Token'],
                    flask.request.headers['X-Service-Catalog'],
                    flask.request.headers['X-User-Name'],
                    flask.request.headers['X-Tenant-Name'],
                    flask.request.headers['X-Roles'].split(','))
                context.set_ctx(ctx)

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()
                #add args 
                else:
                    kwargs.update(flask.request.args.to_dict())
                try:
                    return func(**kwargs)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, 'Internal Server Error', e)
开发者ID:qinweiwei,项目名称:sahara,代码行数:33,代码来源:api.py


示例3: handler

            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug("Rest.route.decorator.handler, kwargs={kwargs}"
                          .format(kwargs=kwargs))

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                kwargs.pop("tenant_id")
                req_id = flask.request.environ.get(oslo_req_id.ENV_REQUEST_ID)
                ctx = context.Context(
                    flask.request.headers['X-User-Id'],
                    flask.request.headers['X-Tenant-Id'],
                    flask.request.headers['X-Auth-Token'],
                    flask.request.headers['X-Service-Catalog'],
                    flask.request.headers['X-User-Name'],
                    flask.request.headers['X-Tenant-Name'],
                    flask.request.headers['X-Roles'].split(','),
                    request_id=req_id)
                context.set_ctx(ctx)
                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                try:
                    return func(**kwargs)
                except ex.Forbidden as e:
                    return access_denied(e)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, 'Internal Server Error', e)
开发者ID:lhcxx,项目名称:sahara,代码行数:35,代码来源:api.py


示例4: admin_context

def admin_context():
    ctx = context.get_admin_context()
    context.set_ctx(ctx)
    try:
        yield
    finally:
        context.set_ctx(None)
开发者ID:openstack,项目名称:sahara,代码行数:7,代码来源:main.py


示例5: version_list

 def version_list():
     context.set_ctx(None)
     return api_utils.render({
         "versions": [
             {"id": "v1.0", "status": "CURRENT"}
         ]
     })
开发者ID:COSHPC,项目名称:sahara,代码行数:7,代码来源:main.py


示例6: terminate_unneeded_clusters

    def terminate_unneeded_clusters(self, ctx):
        LOG.debug('Terminating unneeded clusters')
        ctx = context.get_admin_context()
        context.set_ctx(ctx)
        for cluster in conductor.cluster_get_all(ctx, status='Active'):
            if not cluster.is_transient:
                continue

            jc = conductor.job_execution_count(ctx,
                                               end_time=None,
                                               cluster_id=cluster.id)

            if jc > 0:
                continue

            cluster_updated_at = timeutils.normalize_time(
                timeutils.parse_isotime(cluster.updated_at))
            current_time = timeutils.utcnow()
            spacing = timeutils.delta_seconds(cluster_updated_at, current_time)
            if spacing < CONF.min_transient_cluster_active_time:
                continue

            if CONF.use_identity_api_v3:
                trusts.use_os_admin_auth_token(cluster)
                api.terminate_cluster(cluster.id)
                LOG.debug('Terminated cluster %s with id %s' %
                          (cluster.name, cluster.id))
            else:
                if cluster.status != 'AwaitingTermination':
                    conductor.cluster_update(
                        ctx,
                        cluster,
                        {'status': 'AwaitingTermination'})
        context.set_ctx(None)
开发者ID:AspirinSJL,项目名称:sahara,代码行数:34,代码来源:periodic.py


示例7: test_is_auth_capable_for_user_ctx

 def test_is_auth_capable_for_user_ctx(self):
     existing_ctx = context.ctx()
     try:
         ctx = context.Context('test_user', 'tenant_1', 'test_auth_token',
                               {"network": "aURL"}, remote_semaphore='123')
         self.assertTrue(ctx.is_auth_capable())
     finally:
         context.set_ctx(existing_ctx)
开发者ID:stannie42,项目名称:sahara,代码行数:8,代码来源:test_context.py


示例8: setup_context

 def setup_context(self, username="test_user", tenant_id="tenant_1",
                   token="test_auth_token", tenant_name='test_tenant',
                   **kwargs):
     self.addCleanup(context.set_ctx,
                     context.ctx() if context.has_ctx() else None)
     context.set_ctx(context.Context(
         username=username, tenant_id=tenant_id,
         token=token, service_catalog={},
         tenant_name=tenant_name, **kwargs))
开发者ID:COSHPC,项目名称:sahara,代码行数:9,代码来源:base.py


示例9: check_for_zombie_proxy_users

 def check_for_zombie_proxy_users(self, ctx):
     ctx = context.get_admin_context()
     context.set_ctx(ctx)
     for user in p.proxy_domain_users_list():
         if user.name.startswith('job_'):
             je_id = user.name[4:]
             je = conductor.job_execution_get(ctx, je_id)
             if je is None or (je.info['status'] in
                               edp.JOB_STATUSES_TERMINATED):
                 LOG.debug('Found zombie proxy user {username}'.format(
                     username=user.name))
                 p.proxy_user_delete(user_id=user.id)
     context.set_ctx(None)
开发者ID:YongchaoTIAN,项目名称:sahara,代码行数:13,代码来源:periodic.py


示例10: terminate_unneeded_clusters

        def terminate_unneeded_clusters(self, ctx):
            LOG.debug('Terminating unneeded transient clusters')
            ctx = context.get_admin_context()
            context.set_ctx(ctx)
            for cluster in conductor.cluster_get_all(ctx, status='Active'):
                if not cluster.is_transient:
                    continue

                jc = conductor.job_execution_count(ctx,
                                                   end_time=None,
                                                   cluster_id=cluster.id)

                if jc > 0:
                    continue

                cluster_updated_at = timeutils.normalize_time(
                    timeutils.parse_isotime(cluster.updated_at))
                current_time = timeutils.utcnow()
                spacing = timeutils.delta_seconds(cluster_updated_at,
                                                  current_time)
                if spacing < CONF.min_transient_cluster_active_time:
                    continue

                if CONF.use_identity_api_v3:
                    trusts.use_os_admin_auth_token(cluster)

                    LOG.info(_LI('Terminating transient cluster %(cluster)s '
                                 'with id %(id)s'),
                             {'cluster': cluster.name, 'id': cluster.id})

                    try:
                        ops.terminate_cluster(cluster.id)
                    except Exception as e:
                        LOG.info(_LI('Failed to terminate transient cluster '
                                 '%(cluster)s with id %(id)s: %(error)s.'),
                                 {'cluster': cluster.name,
                                  'id': cluster.id,
                                  'error': six.text_type(e)})

                else:
                    if cluster.status != 'AwaitingTermination':
                        conductor.cluster_update(
                            ctx,
                            cluster,
                            {'status': 'AwaitingTermination'})
            context.set_ctx(None)
开发者ID:a9261,项目名称:sahara,代码行数:46,代码来源:periodic.py


示例11: terminate_unneeded_transient_clusters

        def terminate_unneeded_transient_clusters(self, ctx):
            LOG.debug('Terminating unneeded transient clusters')
            ctx = context.get_admin_context()
            context.set_ctx(ctx)
            for cluster in conductor.cluster_get_all(ctx, status='Active'):
                if not cluster.is_transient:
                    continue

                jc = conductor.job_execution_count(ctx,
                                                   end_time=None,
                                                   cluster_id=cluster.id)

                if jc > 0:
                    continue

                spacing = get_time_since_last_update(cluster)
                if spacing < CONF.min_transient_cluster_active_time:
                    continue

                terminate_cluster(ctx, cluster, description='transient')
                # Add event log info cleanup
                context.ctx().current_instance_info = context.InstanceInfo()
            context.set_ctx(None)
开发者ID:YongchaoTIAN,项目名称:sahara,代码行数:23,代码来源:periodic.py


示例12: terminate_incomplete_clusters

        def terminate_incomplete_clusters(self, ctx):
            if CONF.cleanup_time_for_incomplete_clusters <= 0:
                return

            LOG.debug('Terminating old clusters in non-final state')
            ctx = context.get_admin_context()

            context.set_ctx(ctx)
            # NOTE(alazarev) Retrieving all clusters once in hour for now.
            # Criteria support need to be implemented in sahara db API to
            # have SQL filtering.
            for cluster in conductor.cluster_get_all(ctx):
                if cluster.status in ['Active', 'Error', 'Deleting']:
                    continue

                spacing = get_time_since_last_update(cluster)
                if spacing < CONF.cleanup_time_for_incomplete_clusters * 3600:
                    continue

                terminate_cluster(ctx, cluster, description='incomplete')
                # Add event log info cleanup
                context.ctx().current_instance_info = context.InstanceInfo()
            context.set_ctx(None)
开发者ID:YongchaoTIAN,项目名称:sahara,代码行数:23,代码来源:periodic.py


示例13: teardown_request

 def teardown_request(_ex=None):
     context.set_ctx(None)
开发者ID:COSHPC,项目名称:sahara,代码行数:2,代码来源:main.py


示例14: run_method

 def run_method(ctx, **kwargs):
     context.set_ctx(context.Context(**ctx))
     try:
         return method(**kwargs)
     finally:
         context.set_ctx(None)
开发者ID:a9261,项目名称:sahara,代码行数:6,代码来源:rpc.py


示例15: setUp

 def setUp(self):
     super(ContextTest, self).setUp()
     self.useFixture(fixtures.FakeLogger('sahara'))
     ctx = context.Context('test_user', 'tenant_1', 'test_auth_token', {},
                           remote_semaphore='123')
     context.set_ctx(ctx)
开发者ID:stannie42,项目名称:sahara,代码行数:6,代码来源:test_context.py


示例16: setUp

 def setUp(self):
     ctx = context.Context('test_user', 'tenant_1', 'test_auth_token', {},
                           remote_semaphore='123')
     context.set_ctx(ctx)
开发者ID:esala116,项目名称:sahara,代码行数:4,代码来源:test_context.py


示例17: setUp

 def setUp(self):
     super(TopologyTestCase, self).setUp()
     context.set_ctx(context.Context(None, None, None, None))
开发者ID:Chinmoy-Dey,项目名称:sahara,代码行数:3,代码来源:test_topology.py


示例18: set_ctx

def set_ctx(new_ctx, **kwargs):
    context.set_ctx(new_ctx)
开发者ID:openstack,项目名称:sahara,代码行数:2,代码来源:context.py


示例19: setUp

 def setUp(self):
     context.set_ctx(context.Context(None, None, None, None))
开发者ID:AspirinSJL,项目名称:sahara,代码行数:2,代码来源:test_topology.py


示例20: update_job_statuses

 def update_job_statuses(self, ctx):
     LOG.debug('Updating job statuses')
     ctx = context.get_admin_context()
     context.set_ctx(ctx)
     job_manager.update_job_statuses()
     context.set_ctx(None)
开发者ID:YongchaoTIAN,项目名称:sahara,代码行数:6,代码来源:periodic.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python context.set_current_instance_id函数代码示例发布时间:2022-05-27
下一篇:
Python context.current函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap