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

Python context.extract_context_from_environ函数代码示例

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

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



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

示例1: get_one

 def get_one(self, _id):
     context = t_context.extract_context_from_environ()
     image = self.client.get_images(context, _id)
     if not image:
         pecan.abort(404, 'Image not found')
         return
     return {'image': image}
开发者ID:Ronghui,项目名称:tricircle,代码行数:7,代码来源:image.py


示例2: post

    def post(self, **kw):
        context = t_context.extract_context_from_environ()
        if not context.is_admin:
            pecan.abort(400, 'Admin role required to create aggregates')
            return
        if 'aggregate' not in kw:
            pecan.abort(400, 'Request body not found')
            return

        host_aggregate = kw['aggregate']
        name = host_aggregate['name'].strip()
        avail_zone = host_aggregate.get('availability_zone')
        if avail_zone:
            avail_zone = avail_zone.strip()

        try:
            with context.session.begin():
                aggregate = az_ag.create_ag_az(context,
                                               ag_name=name,
                                               az_name=avail_zone)
        except db_exc.DBDuplicateEntry:
            pecan.abort(409, 'Aggregate already exists')
            return
        except Exception:
            pecan.abort(500, 'Fail to create host aggregate')
            return

        return {'aggregate': aggregate}
开发者ID:Ronghui,项目名称:tricircle,代码行数:28,代码来源:aggregate.py


示例3: get_all

    def get_all(self):

        # TODO(joehuang): here should return link instead,
        # now combined with 'detail'

        context = t_context.extract_context_from_environ()
        return {'volumes': self._get_all(context)}
开发者ID:Ronghui,项目名称:tricircle,代码行数:7,代码来源:volume.py


示例4: delete

    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        # TODO(joehuang): get the release of top and bottom
        t_release = 'MITATA'
        b_release = 'MITATA'

        s_ctx = self._get_res_routing_ref(context, _id, request.url)
        if not s_ctx:
            return Response(_('Failed to find resource'), 404)

        if s_ctx['b_url'] == '':
            return Response(_('bottom pod endpoint incorrect'), 404)

        b_headers = self._convert_header(t_release,
                                         b_release,
                                         request.headers)

        resp = hclient.forward_req(context, 'DELETE',
                                   b_headers,
                                   s_ctx['b_url'],
                                   request.body)

        response.status = resp.status_code

        # don't remove the resource routing for delete is async. operation
        # remove the routing when query is executed but not find

        # No content in the resp actually
        return {}
开发者ID:Ronghui,项目名称:tricircle,代码行数:30,代码来源:volume.py


示例5: get_one

 def get_one(self, _id):
     # NOTE(zhiyuan) this function handles two kinds of requests
     # GET /flavors/flavor_id
     # GET /flavors/detail
     context = t_context.extract_context_from_environ()
     if _id == 'detail':
         with context.session.begin():
             flavors = core.query_resource(context, models.InstanceTypes,
                                           [], [])
             for flavor in flavors:
                 flavor['id'] = flavor['flavorid']
                 del flavor['flavorid']
             return {'flavors': flavors}
     else:
         with context.session.begin():
             flavors = core.query_resource(context, models.InstanceTypes,
                                           [{'key': 'flavorid',
                                             'comparator': 'eq',
                                             'value': _id}], [])
             if not flavors:
                 pecan.abort(404, 'Flavor not found')
                 return
             flavor = flavors[0]
             flavor['id'] = flavor['flavorid']
             del flavor['flavorid']
             return {'flavor': flavor}
开发者ID:Ronghui,项目名称:tricircle,代码行数:26,代码来源:flavor.py


示例6: put

    def put(self, _id, **kw):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_ROUTINGS_PUT):
            return utils.format_api_error(
                403, _('Unauthorized to update resource routing'))

        try:
            db_api.get_resource_routing(context, _id)
        except t_exceptions.ResourceNotFound:
            return utils.format_api_error(404,
                                          _('Resource routing not found'))

        if 'routing' not in kw:
            return utils.format_api_error(
                400, _('Request body not found'))

        update_dict = kw['routing']

        # values to be updated should not be empty
        for field in update_dict:
            value = update_dict.get(field)
            if value is None or len(value.strip()) == 0:
                return utils.format_api_error(
                    400, _("Field %(field)s can not be empty") % {
                        'field': field})

        # the resource type should be properly provisioned.
        if 'resource_type' in update_dict:
            if not constants.is_valid_resource_type(
                    update_dict['resource_type']):
                return utils.format_api_error(
                    400, _('There is no such resource type'))

        # the pod with new pod_id should exist in pod table
        if 'pod_id' in update_dict:
            new_pod_id = update_dict.get('pod_id')
            try:
                # find the pod through the pod_id and verify whether it exists
                db_api.get_pod(context, new_pod_id)
            except t_exceptions.ResourceNotFound:
                return utils.format_api_error(
                    400, _("The pod %(new_pod_id)s doesn't"
                           " exist") % {'new_pod_id': new_pod_id})
            except Exception as e:
                LOG.exception('Failed to update resource routing: '
                              '%(exception)s ', {'exception': e})
                return utils.format_api_error(
                    500, _('Failed to update resource routing'))

        try:
            routing_updated = db_api.update_resource_routing(
                context, _id, update_dict)
            return {'routing': routing_updated}
        except Exception as e:
            LOG.exception('Failed to update resource routing: '
                          '%(exception)s ', {'exception': e})
            return utils.format_api_error(
                500, _('Failed to update resource routing'))
开发者ID:LongXQ,项目名称:tricircle,代码行数:59,代码来源:routing.py


示例7: get_all

 def get_all(self):
     context = t_context.extract_context_from_environ()
     with context.session.begin():
         flavors = core.query_resource(context, models.InstanceTypes,
                                       [], [])
         return {'flavors': [dict(
             [('id', flavor['flavorid']),
              ('name', flavor['name'])]) for flavor in flavors]}
开发者ID:Ronghui,项目名称:tricircle,代码行数:8,代码来源:flavor.py


示例8: get_one

 def get_one(self, _id):
     context = t_context.extract_context_from_environ()
     try:
         with context.session.begin():
             aggregate = az_ag.get_one_ag(context, _id)
             return {'aggregate': aggregate}
     except t_exc.ResourceNotFound:
         pecan.abort(404, 'Aggregate not found')
         return
开发者ID:Ronghui,项目名称:tricircle,代码行数:9,代码来源:aggregate.py


示例9: delete

 def delete(self, _id):
     context = t_context.extract_context_from_environ()
     try:
         with context.session.begin():
             az_ag.delete_ag(context, _id)
             pecan.response.status = 200
     except t_exc.ResourceNotFound:
         pecan.abort(404, 'Aggregate not found')
         return
开发者ID:Ronghui,项目名称:tricircle,代码行数:9,代码来源:aggregate.py


示例10: put

    def put(self, **kw):

        context = t_context.extract_context_from_environ()
        if not context.is_admin:
            # TODO(joahuang): changed to policy control later
            # to support reseller admin mode
            return Response(_('Admin role required to update quota'), 409)

        return self._quota_action('put', **kw)
开发者ID:Ronghui,项目名称:tricircle,代码行数:9,代码来源:quota_sets.py


示例11: get_all

    def get_all(self):
        context = t_context.extract_context_from_environ()

        try:
            with context.session.begin():
                aggregates = az_ag.get_all_ag(context)
        except Exception:
            pecan.abort(500, 'Fail to get all host aggregates')
            return
        return {'aggregates': aggregates}
开发者ID:Ronghui,项目名称:tricircle,代码行数:10,代码来源:aggregate.py


示例12: post

    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if not t_context.is_admin_context(context):
            pecan.abort(400, _('Admin role required to create bindings'))
            return

        if 'pod_binding' not in kw:
            pecan.abort(400, _('Request body not found'))
            return

        pod_b = kw['pod_binding']
        tenant_id = pod_b.get('tenant_id', '').strip()
        pod_id = pod_b.get('pod_id', '').strip()
        _uuid = uuidutils.generate_uuid()

        if tenant_id == '' or pod_id == '':
            return Response(
                _('Tenant_id and pod_id can not be empty'),
                422)

        # the az_pod_map_id should be exist for in the pod map table
        try:
            with context.session.begin():
                pod = core.get_resource(context, models.Pod,
                                        pod_id)
                if pod.get('az_name') == '':
                    return Response(_('Top region can not be bound'), 422)
        except t_exc.ResourceNotFound:
            return Response(_('pod_id not found in pod'), 422)
        except Exception as e:
            LOG.error(_LE('Fail to create pod binding: %(exception)s'),
                      {'exception': e})
            pecan.abort(500, _('Fail to create pod binding'))
            return

        try:
            with context.session.begin():
                pod_binding = core.create_resource(context, models.PodBinding,
                                                   {'id': _uuid,
                                                    'tenant_id': tenant_id,
                                                    'pod_id': pod_id})
        except db_exc.DBDuplicateEntry:
            return Response(_('Pod binding already exists'), 409)
        except db_exc.DBConstraintError:
            return Response(_('pod_id not exists in pod'), 422)
        except db_exc.DBReferenceError:
            return Response(_('DB reference not exists in pod'), 422)
        except Exception as e:
            LOG.error(_LE('Fail to create pod binding: %(exception)s'),
                      {'exception': e})
            pecan.abort(500, _('Fail to create pod binding'))
            return

        return {'pod_binding': pod_binding}
开发者ID:Ronghui,项目名称:tricircle,代码行数:55,代码来源:pod.py


示例13: get_one

    def get_one(self, _id):
        context = t_context.extract_context_from_environ()

        if _id == 'detail':
            return {'volumes': self._get_all(context)}

        # TODO(joehuang): get the release of top and bottom
        t_release = 'MITATA'
        b_release = 'MITATA'

        b_headers = self._convert_header(t_release,
                                         b_release,
                                         request.headers)

        s_ctx = self._get_res_routing_ref(context, _id, request.url)
        if not s_ctx:
            return Response(_('Failed to find resource'), 404)

        if s_ctx['b_url'] == '':
            return Response(_('bottom pod endpoint incorrect'), 404)

        resp = hclient.forward_req(context, 'GET',
                                   b_headers,
                                   s_ctx['b_url'],
                                   request.body)

        b_ret_body = jsonutils.loads(resp.content)

        b_status = resp.status_code
        response.status = b_status
        if b_status == 200:
            if b_ret_body.get('volume') is not None:
                b_vol_ret = b_ret_body['volume']
                ret_vol = self._convert_object(b_release, t_release,
                                               b_vol_ret,
                                               res_type=cons.RT_VOLUME)

                pod = self._get_pod_by_top_id(context, _id)
                if pod:
                    ret_vol['availability_zone'] = pod['az_name']

                return {'volume': ret_vol}

        # resource not find but routing exist, remove the routing
        if b_status == 404:
            filters = [{'key': 'top_id', 'comparator': 'eq', 'value': _id},
                       {'key': 'resource_type',
                        'comparator': 'eq',
                        'value': cons.RT_VOLUME}]
            with context.session.begin():
                core.delete_resources(context,
                                      models.ResourceRouting,
                                      filters)
        return b_ret_body
开发者ID:Ronghui,项目名称:tricircle,代码行数:54,代码来源:volume.py


示例14: get_one

    def get_one(self, _id):
        context = t_context.extract_context_from_environ()

        if not t_context.is_admin_context(context):
            pecan.abort(400, _('Admin role required to show pods'))
            return

        try:
            return {'pod': db_api.get_pod(context, _id)}
        except t_exc.ResourceNotFound:
            pecan.abort(404, _('Pod not found'))
            return
开发者ID:Ronghui,项目名称:tricircle,代码行数:12,代码来源:pod.py


示例15: post

    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if 'volumeAttachment' not in kw:
            pecan.abort(400, 'Request body not found')
            return
        body = kw['volumeAttachment']
        if 'volumeId' not in body:
            pecan.abort(400, 'Volume not set')
            return

        server_mappings = db_api.get_bottom_mappings_by_top_id(
            context, self.server_id, constants.RT_SERVER)
        if not server_mappings:
            pecan.abort(404, 'Server not found')
            return
        volume_mappings = db_api.get_bottom_mappings_by_top_id(
            context, body['volumeId'], constants.RT_VOLUME)
        if not volume_mappings:
            pecan.abort(404, 'Volume not found')
            return

        server_pod_name = server_mappings[0][0]['pod_name']
        volume_pod_name = volume_mappings[0][0]['pod_name']
        if server_pod_name != volume_pod_name:
            LOG.error(_LE('Server %(server)s is in pod %(server_pod)s and '
                          'volume %(volume)s is in pod %(volume_pod)s, which '
                          'are not the same.'),
                      {'server': self.server_id,
                       'server_pod': server_pod_name,
                       'volume': body['volumeId'],
                       'volume_pod': volume_pod_name})
            pecan.abort(400, 'Server and volume not in the same pod')
            return

        device = None
        if 'device' in body:
            device = body['device']
            # this regular expression is copied from nova/block_device.py
            match = re.match('(^/dev/x{0,1}[a-z]{0,1}d{0,1})([a-z]+)[0-9]*$',
                             device)
            if not match:
                pecan.abort(400, 'Invalid device path')
                return

        client = self._get_client(server_pod_name)
        volume = client.action_server_volumes(
            context, 'create_server_volume',
            server_mappings[0][1], volume_mappings[0][1], device)
        return {'volumeAttachment': volume.to_dict()}
开发者ID:Ronghui,项目名称:tricircle,代码行数:50,代码来源:volume.py


示例16: delete

    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        if not t_context.is_admin_context(context):
            pecan.abort(400, _('Admin role required to delete bindings'))
            return

        try:
            with context.session.begin():
                core.delete_resource(context, models.PodBinding, _id)
                pecan.response.status = 200
        except t_exc.ResourceNotFound:
            pecan.abort(404, _('Pod binding not found'))
            return
开发者ID:Ronghui,项目名称:tricircle,代码行数:14,代码来源:pod.py


示例17: delete

 def delete(self, _id):
     context = t_context.extract_context_from_environ()
     with context.session.begin():
         flavors = core.query_resource(context, models.InstanceTypes,
                                       [{'key': 'flavorid',
                                         'comparator': 'eq',
                                         'value': _id}], [])
         if not flavors:
             pecan.abort(404, 'Flavor not found')
             return
         core.delete_resource(context,
                              models.InstanceTypes, flavors[0]['id'])
     pecan.response.status = 202
     return
开发者ID:Ronghui,项目名称:tricircle,代码行数:14,代码来源:flavor.py


示例18: get_all

    def get_all(self):
        context = t_context.extract_context_from_environ()

        if not t_context.is_admin_context(context):
            pecan.abort(400, _('Admin role required to list pods'))
            return

        try:
            return {'pods': db_api.list_pods(context)}
        except Exception as e:
            LOG.error(_LE('Fail to list pod: %(exception)s'),
                      {'exception': e})
            pecan.abort(500, _('Fail to list pod'))
            return
开发者ID:Ronghui,项目名称:tricircle,代码行数:14,代码来源:pod.py


示例19: _quota_action

    def _quota_action(self, action, **kw):

        context = t_context.extract_context_from_environ()
        context.project_id = self.owner_tenant_id
        target_tenant_id = self.target_tenant_id
        target_user_id = request.params.get('user_id', None)
        if target_user_id:
            target_user_id.strip()

        qs = quota.QuotaSetOperation(target_tenant_id,
                                     target_user_id)
        quotas = {}
        try:
            if action == 'put':
                quotas = qs.update(context, **kw)
            elif action == 'delete':
                qs.delete(context)
                response.status = 202
                return
            elif action == 'defaults':
                quotas = qs.show_default_quota(context)
            elif action == 'detail':
                quotas = qs.show_detail_quota(context, show_usage=True)

                # remove the allocated field which is not visible in Nova
                for k, v in quotas['quota_set'].iteritems():
                    if k != 'id':
                        v.pop('allocated', None)

            elif action == 'quota-show':
                quotas = qs.show_detail_quota(context, show_usage=False)
            else:
                return Response('Resource not found', 404)
        except t_exceptions.NotFound as e:
            msg = str(e)
            LOG.exception(msg=msg)
            return Response(msg, 404)
        except (t_exceptions.AdminRequired,
                t_exceptions.NotAuthorized,
                t_exceptions.HTTPForbiddenError) as e:
            msg = str(e)
            LOG.exception(msg=msg)
            return Response(msg, 403)
        except Exception as e:
            msg = str(e)
            LOG.exception(msg=msg)
            return Response(msg, 400)

        return {'quota_set': self._build_visible_quota(quotas['quota_set'])}
开发者ID:Ronghui,项目名称:tricircle,代码行数:49,代码来源:quota_sets.py


示例20: post

    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_ROUTINGS_CREATE):
            return utils.format_api_error(
                403, _("Unauthorized to create resource routing"))

        if 'routing' not in kw:
            return utils.format_api_error(
                400, _("Request body not found"))

        routing = kw['routing']

        for field in ('top_id', 'bottom_id', 'pod_id',
                      'project_id', 'resource_type'):
            value = routing.get(field)
            if value is None or len(value.strip()) == 0:
                return utils.format_api_error(
                    400, _("Field %(field)s can not be empty") % {
                        'field': field})

        # the resource type should be properly provisioned.
        resource_type = routing.get('resource_type').strip()
        if not constants.is_valid_resource_type(resource_type):
            return utils.format_api_error(
                400, _('There is no such resource type'))

        try:
            top_id = routing.get('top_id').strip()
            bottom_id = routing.get('bottom_id').strip()
            pod_id = routing.get('pod_id').strip()
            project_id = routing.get('project_id').strip()

            routing = db_api.create_resource_mapping(context, top_id,
                                                     bottom_id, pod_id,
                                                     project_id,
                                                     resource_type)
            if not routing:
                return utils.format_api_error(
                    409, _('Resource routing already exists'))
        except Exception as e:
            LOG.exception('Failed to create resource routing: '
                          '%(exception)s ', {'exception': e})
            return utils.format_api_error(
                500, _('Failed to create resource routing'))

        return {'routing': routing}
开发者ID:LongXQ,项目名称:tricircle,代码行数:47,代码来源:routing.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python context.get_context_from_neutron_context函数代码示例发布时间:2022-05-27
下一篇:
Python model.DBSession类代码示例发布时间: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