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


Python context.extract_context_from_environ函数代码示例

本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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