コード例 #1
0
ファイル: region.py プロジェクト: IterZebra/tricircle
    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if 'region' not in kw:
            pecan.abort(400, _('Request body region not found'))
            return
        print 'MaXiao kw '+str(request.context['request_data'])
        region = request.context['request_data']['region']
        region_name = region.get('region_name', '').strip()
        _uuid = uuidutils.generate_uuid()
        try:
            with context.session.begin():
                new_region = core.create_resource(
                    context, models.Region,
                    {'id': _uuid,
                     'region_name': region_name})
        except db_exc.DBDuplicateEntry as e1:
            LOG.exception('Record already exists on %(region_name)s: '
                          '%(exception)s',
                          {'region_name': region_name,
                           'exception': e1})
            return Response(_('Record already exists'), 409)
        except Exception as e2:
            LOG.exception('Failed to create region: %(region_name)s,'
                          '%(exception)s ',
                          {'region_name': region_name,
                           'exception': e2})
            return Response(_('Failed to create region'), 500)

        return {'region': new_region}
コード例 #2
0
ファイル: test_hooks.py プロジェクト: alex-devops/pecan
            def on_error(self, state, e):
                run_hook.append('error')

                r = Response()
                r.text = u_('on_error')

                return r
コード例 #3
0
ファイル: pod.py プロジェクト: zwxhnu/trio2o
    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 pods'))
            return

        try:
            with context.session.begin():
                pod = core.get_resource(context, models.Pod, _id)
                if pod is not None:
                    ag_name = utils.get_ag_name(pod['pod_name'])
                    ag = az_ag.get_ag_by_name(context, ag_name)
                    if ag is not None:
                        az_ag.delete_ag(context, ag['id'])
                core.delete_resource(context, models.Pod, _id)
                pecan.response.status = 200
                return {}
        except t_exc.ResourceNotFound:
            return Response(_('Pod not found'), 404)
        except Exception as e:
            LOG.exception(
                _LE('Failed to delete pod: %(pod_id)s,'
                    '%(exception)s'), {
                        'pod_id': _id,
                        'exception': e
                    })

            return Response(_('Failed to delete pod'), 500)
コード例 #4
0
ファイル: region.py プロジェクト: IterZebra/tricircle
    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE):
            pecan.abort(401, _('Unauthorized to delete regions'))
            return

        try:
            with context.session.begin():
                print "MaXiao 111  delete region has dcs "
                region_object = core.get_resource_object(context, models.Region, _id)
                print "MaXiao delete region has dcs :"+str(region_result)
                if len(region_object.dcs)>0:
                    raise t_exceptions.InUse("Specified region has dc(s)")
                core.delete_resource(context, models.Region, _id)
                pecan.response.status = 200
                return {}
        except t_exceptions.InUse:
            return Response(_('Specified region has dcs'), 400)
        except t_exceptions.ResourceNotFound:
            return Response(_('Region not found'), 404)
        except Exception as e:
            LOG.exception('Failed to delete region: %(region_id)s,'
                          '%(exception)s',
                          {'region_id': _id,
                           'exception': e})

            return Response(_('Failed to delete region'), 500)
コード例 #5
0
ファイル: pod.py プロジェクト: OpenCloudNeXt/trio2o
    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE):
            pecan.abort(401, _('Unauthorized to delete pods'))
            return

        try:
            with context.session.begin():
                pod = core.get_resource(context, models.Pod, _id)
                if pod is not None:
                    ag_name = utils.get_ag_name(pod['pod_name'])
                    ag = az_ag.get_ag_by_name(context, ag_name)
                    if ag is not None:
                        az_ag.delete_ag(context, ag['id'])
                core.delete_resource(context, models.Pod, _id)
                pecan.response.status = 200
        except t_exc.ResourceNotFound:
            return Response(_('Pod not found'), 404)
        except Exception as e:
            LOG.exception(
                _LE('Failed to delete pod: %(pod_id)s,'
                    '%(exception)s'), {
                        'pod_id': _id,
                        'exception': e
                    })

            return Response(_('Failed to delete pod'), 500)
コード例 #6
0
            def on_error(self, state, e):
                run_hook.append("error")

                r = Response()
                r.text = u_("on_error")

                return r
コード例 #7
0
ファイル: volume.py プロジェクト: paperandsoap/tricircle
    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        # TODO(joehuang): get the release of top and bottom
        t_release = cons.R_MITAKA
        b_release = cons.R_MITAKA

        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 response
コード例 #8
0
    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE):
            pecan.abort(401, _('Unauthorized to delete dcs'))
            return

        try:
            with context.session.begin():
                region_object = core.get_resource_object(context, models.DC, _id)
                if len(region_object.fabrics) >0:
                    raise t_exceptions.InUse("Specified dc has fabric(s)")
                if len(region_object.core_routers) >0:
                    raise t_exceptions.InUse("Specified dc has core_router(s)")
                core.delete_resource(context, models.DC, _id)
                pecan.response.status = 200
                return {}
        except t_exceptions.InUse:
            return Response(_('Specified region has dcs/core_routers'), 400)
        except t_exceptions.ResourceNotFound:
            return Response(_('DC not found'), 404)
        except Exception as e:
            LOG.exception('Failed to delete dc: %(dc_id)s,'
                          '%(exception)s',
                          {'dc_id': _id,
                           'exception': e})

            return Response(_('Failed to delete dc'), 500)
コード例 #9
0
ファイル: volume.py プロジェクト: paperandsoap/tricircle
    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 = cons.R_MITAKA
        b_release = cons.R_MITAKA

        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
コード例 #10
0
ファイル: quota_sets.py プロジェクト: paperandsoap/tricircle
    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'])}
コード例 #11
0
    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_CREATE):
            pecan.abort(401, _('Unauthorized to create tricircle resource'))
            return

        if 'tricircle_resource' not in kw:
            pecan.abort(400, _('Request body tricircle_resource not found'))
            return
        tricircle_resource = request.context['request_data']['tricircle_resource']

        tricircle_resource_id= tricircle_resource.get('id', '').strip()
        tricircle_resource_name = tricircle_resource.get('name', '').strip()
        region_name= tricircle_resource.get('region_name', '').strip()
        project_id= tricircle_resource.get('project_id', '').strip()
        resource_type= tricircle_resource.get('resource_type', '').strip()
        admin_state_up = tricircle_resource.get('admin_state_up',True)
        status = tricircle_resource.get('status',"DOWN")


        try:
            with context.session.begin():
                new_tricircle_resource= core.create_resource(
                    context, models.TricircleResource,
                    {'id': tricircle_resource_id,
                     'name':tricircle_resource_name,
                     'region_name':region_name,
                     'resource_type':resource_type,
                     'project_id': project_id,
                     'admin_state_up':admin_state_up,
                     'status':status})
    
        except db_exc.DBDuplicateEntry as e1:
            LOG.exception('Record already exists on'
                          'tricircle_resource_id%(tricircle_resource_id)s: '
                          '%(exception)s',
                          {'tricircle_resource_id':tricircle_resource_id,
                           'exception': e1})
            return Response(_('Record already exists'), 409)
        except Exception as e2:
            LOG.exception('Failed to create tricircle_resource :'
                          'tricircle_resource_id: %(tricircle_resource_id)s,'
                          '%(exception)s ',
                          {'tricircle_resource_id': tricircle_resource_id,
                           'exception': e2})
            return Response(_('Failed to create tricircle_resource'), 500)

        return {'tricircle_resource': new_tricircle_resource}
コード例 #12
0
ファイル: quota_sets.py プロジェクト: paperandsoap/tricircle
    def get_all(self):

        # TODO(joehuang): add policy controll here

        context = t_context.extract_context_from_environ()
        context.project_id = self.tenant_id
        target_tenant_id = request.params.get('tenant_id', None)
        if target_tenant_id:
            target_tenant_id.strip()
        else:
            return Response('tenant_id not given', 400)

        qs = quota.QuotaSetOperation(target_tenant_id,
                                     None)
        try:
            quotas = qs.show_detail_quota(context, show_usage=True)
        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)

        # TODO(joehuang): add API rate limits later
        ret = {
            'limits': {
                'rate': {},
                'absolute': {},
            },
        }

        ret['limits']['absolute'].update(
            build_absolute_limits(quotas['quota_set']))
        ret['limits']['absolute'].update(
            build_used_limits(quotas['quota_set']))

        return ret
コード例 #13
0
ファイル: quota_sets.py プロジェクト: zwxhnu/trio2o
    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)
コード例 #14
0
    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if 'fabric' not in kw:
            pecan.abort(400, _('Request body fabric not found'))
            return
        print 'MaXiao kw ' + str(request.context['request_data'])
        fabric = request.context['request_data']['fabric']
        fabric_name = fabric.get('fabric_name', '').strip()
        dc_id = fabric.get('dc_id', '').strip()
        _uuid = uuidutils.generate_uuid()
        try:
            with context.session.begin():
                core.get_resource(context, models.DC, dc_id)
                new_fabric = core.create_resource(context, models.Fabric, {
                    'id': _uuid,
                    'fabric_name': fabric_name,
                    'dc_id': dc_id
                })
        except t_exceptions.ResourceNotFound:
            return Response(_('Specified dc not found'), 404)
        except db_exc.DBDuplicateEntry as e1:
            LOG.exception(
                'Record already exists on %(fabric_name)s,'
                'dc_id: %(dc_id)s,'
                '%(exception)s', {
                    'fabric_name': fabric_name,
                    'dc_id': dc_id,
                    'exception': e1
                })
            return Response(_('Record already exists'), 409)
        except Exception as e2:
            LOG.exception(
                'Failed to create fabric: %(fabric_name)s,'
                'dc_id: %(dc_id)s,'
                '%(exception)s ', {
                    'fabric_name': fabric_name,
                    'dc_id': dc_id,
                    'exception': e2
                })
            return Response(_('Failed to create fabric'), 500)

        return {'fabric': new_fabric}
コード例 #15
0
    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE):
            pecan.abort(401, _('Unauthorized to delete tricircle_resources'))
            return

        try:
            with context.session.begin():
                core.delete_resource(context, models.TricircleResource, _id)
                pecan.response.status = 200
                return {}
        except t_exceptions.ResourceNotFound:
            return Response(_('Firewall gateway not found'), 404)
        except Exception as e:
            LOG.exception('Failed to delete tricircle_resource: %(tricircle_resource_id)s,'
                          '%(exception)s',
                          {'tricircle_resource_id': _id,
                           'exception': e})

            return Response(_('Failed to delete tricircle_resource'), 500)
コード例 #16
0
    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE):
            pecan.abort(401, _('Unauthorized to delete dynamic_peering_connections'))
            return

        try:
            with context.session.begin():
                core.delete_resource(context, models.DynamicPeeringConnection, _id)
                pecan.response.status = 200
                return {}
        except t_exceptions.ResourceNotFound:
            return Response(_('Dynamic Peering Connection not found'), 404)
        except Exception as e:
            LOG.exception('Failed to delete dynamic_peering_connection: %(dynamic_peering_connection_id)s,'
                          '%(exception)s',
                          {'dynamic_peering_connection_id': _id,
                           'exception': e})

            return Response(_('Failed to delete dynamic_peering_connection'), 500)
コード例 #17
0
ファイル: pod.py プロジェクト: paperandsoap/tricircle
    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.exception(
                _LE('Failed to get_resource for pod_id: '
                    '%(pod_id)s ,'
                    '%(exception)s '), {
                        'pod_id': pod_id,
                        'exception': e
                    })
            pecan.abort(500, _('Failed 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.exception(_LE('Failed to create pod binding: %(exception)s '),
                          {'exception': e})
            pecan.abort(500, _('Failed to create pod binding'))
            return

        return {'pod_binding': pod_binding}
コード例 #18
0
    def delete(self, _id):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE):
            pecan.abort(401, _('Unauthorized to delete pods'))
            return

        try:
            with context.session.begin():
                core.delete_resource(context, models.Pod, _id)
                pecan.response.status = 200
                return {}
        except t_exc.ResourceNotFound:
            return Response(_('Pod not found'), 404)
        except Exception as e:
            LOG.exception(
                _LE('Failed to delete pod: %(pod_id)s,'
                    '%(exception)s'), {
                        'pod_id': _id,
                        'exception': e
                    })

            return Response(_('Failed to delete pod'), 500)
コード例 #19
0
ファイル: quota_sets.py プロジェクト: zwxhnu/trio2o
    def delete(self):
        """Delete Quota for a particular tenant.

        This works for hierarchical and non-hierarchical projects. For
        hierarchical projects only immediate parent admin or the
        CLOUD admin are able to perform a delete.

        :param id: target project id that needs to be deleted
        """

        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 delete quota'), 409)

        kw = {}
        return self._quota_action('delete', **kw)
コード例 #20
0
ファイル: pod.py プロジェクト: OpenCloudNeXt/trio2o
    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_BINDINGS_CREATE):
            pecan.abort(401, _('Unauthorized 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()

        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.exception(
                _LE('Failed to get_resource for pod_id: '
                    '%(pod_id)s ,'
                    '%(exception)s '), {
                        'pod_id': pod_id,
                        'exception': e
                    })
            pecan.abort(500, _('Failed to create pod binding'))
            return

        try:
            pod_binding = db_api.create_pod_binding(context, tenant_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.exception(_LE('Failed to create pod binding: %(exception)s '),
                          {'exception': e})
            pecan.abort(500, _('Failed to create pod binding'))
            return

        return {'pod_binding': pod_binding}
コード例 #21
0
ファイル: pod.py プロジェクト: OpenCloudNeXt/trio2o
    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_CREATE):
            pecan.abort(401, _('Unauthorized to create pods'))
            return

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

        pod = kw['pod']

        # if az_name is null, and there is already one in db
        pod_name = pod.get('pod_name', '').strip()
        pod_az_name = pod.get('pod_az_name', '').strip()
        dc_name = pod.get('dc_name', '').strip()
        az_name = pod.get('az_name', '').strip()
        _uuid = uuidutils.generate_uuid()

        if az_name == '' and pod_name == '':
            return Response(_('Valid pod_name is required for top region'),
                            422)

        if az_name != '' and pod_name == '':
            return Response(_('Valid pod_name is required for pod'), 422)

        if pod.get('az_name') is None:
            if self._get_top_region(context) != '':
                return Response(_('Top region already exists'), 409)

        # if az_name is not null, then the pod region name should not
        # be same as that the top region
        if az_name != '':
            if self._get_top_region(context) == pod_name and pod_name != '':
                return Response(
                    _('Pod region name duplicated with the top region name'),
                    409)

        # to create the top region, make the pod_az_name to null value
        if az_name == '':
            pod_az_name = ''

        try:
            with context.session.begin():
                # if not top region,
                # then add corresponding ag and az for the pod
                if az_name != '':
                    ag_name = utils.get_ag_name(pod_name)
                    aggregate = az_ag.create_ag_az(context,
                                                   ag_name=ag_name,
                                                   az_name=az_name)
                    if aggregate is None:
                        return Response(_('Ag creation failure'), 400)

                new_pod = core.create_resource(
                    context, models.Pod, {
                        'pod_id': _uuid,
                        'pod_name': pod_name,
                        'pod_az_name': pod_az_name,
                        'dc_name': dc_name,
                        'az_name': az_name
                    })
        except db_exc.DBDuplicateEntry as e1:
            LOG.exception(
                _LE('Record already exists on %(pod_name)s: '
                    '%(exception)s'), {
                        'pod_name': pod_name,
                        'exception': e1
                    })
            return Response(_('Record already exists'), 409)
        except Exception as e2:
            LOG.exception(
                _LE('Failed to create pod: %(pod_name)s,'
                    'pod_az_name: %(pod_az_name)s,'
                    'dc_name: %(dc_name)s,'
                    'az_name: %(az_name)s'
                    '%(exception)s '), {
                        'pod_name': pod_name,
                        'pod_az_name': pod_az_name,
                        'dc_name': dc_name,
                        'az_name': az_name,
                        'exception': e2
                    })
            return Response(_('Failed to create pod'), 500)

        return {'pod': new_pod}
コード例 #22
0
    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_CREATE):
            pecan.abort(401, _('Unauthorized to create pods'))
            return

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

        pod = kw['pod']

        # if az_name is null, and there is already one in db
        region_name = pod.get('region_name', '').strip()
        pod_az_name = pod.get('pod_az_name', '').strip()
        dc_name = pod.get('dc_name', '').strip()
        az_name = pod.get('az_name', '').strip()
        _uuid = uuidutils.generate_uuid()
        top_region_name = self._get_top_region(context)

        if az_name == '':
            if region_name == '':
                return Response(
                    _('Valid region_name is required for top region'), 422)

            if top_region_name != '':
                return Response(_('Top region already exists'), 409)
            # to create the top region, make the pod_az_name to null value
            pod_az_name = ''

        if az_name != '':
            if region_name == '':
                return Response(_('Valid region_name is required for pod'),
                                422)
            # region_name != ''
            # then the pod region name should not be same as the top region
            if top_region_name == region_name:
                return Response(
                    _('Pod region name duplicated with the top region name'),
                    409)

        try:
            with context.session.begin():
                new_pod = core.create_resource(
                    context, models.Pod, {
                        'pod_id': _uuid,
                        'region_name': region_name,
                        'pod_az_name': pod_az_name,
                        'dc_name': dc_name,
                        'az_name': az_name
                    })
        except db_exc.DBDuplicateEntry as e1:
            LOG.exception(
                'Record already exists on %(region_name)s: '
                '%(exception)s', {
                    'region_name': region_name,
                    'exception': e1
                })
            return Response(_('Record already exists'), 409)
        except Exception as e2:
            LOG.exception(
                'Failed to create pod: %(region_name)s,'
                'pod_az_name: %(pod_az_name)s,'
                'dc_name: %(dc_name)s,'
                'az_name: %(az_name)s'
                '%(exception)s ', {
                    'region_name': region_name,
                    'pod_az_name': pod_az_name,
                    'dc_name': dc_name,
                    'az_name': az_name,
                    'exception': e2
                })
            return Response(_('Failed to create pod'), 500)

        return {'pod': new_pod}
コード例 #23
0
    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_CREATE):
            pecan.abort(401, _('Unauthorized to create dynamic peering connection'))
            return

        if 'dynamic_peering_connection' not in kw:
            pecan.abort(400, _('Request body dynamic_peering_connection not found'))
            return
        print 'MaXiao kw '+str(request.context['request_data'])
        dynamic_peering_connection = request.context['request_data']['dynamic_peering_connection']

        dynamic_peering_connection_name = dynamic_peering_connection.get('dynamic_peering_connection_name', '').strip()
        project_id= dynamic_peering_connection.get('project_id', '').strip()
        local_router_id= dynamic_peering_connection.get('local_router_id', '').strip()
        peering_router_id= dynamic_peering_connection.get('peering_router_id', '').strip()
        if local_router_id == peering_router_id:
            pecan.abort(400, _('Request body local_router_id is same with peering_router_id'))
            return
         
        description = dynamic_peering_connection.get('description', '').strip()
        admin_state_up = dynamic_peering_connection.get('admin_state_up',True)
        status = dynamic_peering_connection.get('status',"DOWN")

        _uuid = uuidutils.generate_uuid()

        try:
            with context.session.begin():
                core.get_resource(context, models.CoreRouter, local_router_id)
                core.get_resource(context, models.CoreRouter, peering_router_id)
                new_dynamic_peering_connection = core.create_resource(
                    context, models.DynamicPeeringConnection,
                    {'dynamic_peering_connection_id': _uuid,
                     'dynamic_peering_connection_name':dynamic_peering_connection_name,
                     'project_id': project_id,
                     'local_router_id': local_router_id,
                     'peering_router_id':peering_router_id,
                     'admin_state_up':admin_state_up,
                     'status':status,
                    'description':description})
        except t_exceptions.ResourceNotFound as e0:
            LOG.exception('Record router not exists on'
                          'local_router_id %(local_router_id)s: '
                          'peering_router_id %(peering_router_id)s: '
                          '%(exception)s',
                          {'local_router_id': local_router_id,
                           'peering_router_id': peering_router_id,
                           'exception': e0})
            pecan.abort(404, _('Failed to create dynamic peering connection,core router not found'))
            return
    
        except db_exc.DBDuplicateEntry as e1:
            LOG.exception('Record already exists on'
                          'local_router_id %(local_router_id)s: '
                          'peering_router_id %(peering_router_id)s: '
                          '%(exception)s',
                          {'local_router_id': local_router_id,
                           'peering_router_id': peering_router_id,
                           'exception': e1})
            return Response(_('Record already exists'), 409)
        except Exception as e2:
            LOG.exception('Failed to create dynamic_peering_connection :'
                          'local_router_id: %(local_router_id)s,'
                          'peering_router_id: %(peering_router_id)s,'
                          '%(exception)s ',
                          {'local_router_id': local_router_id,
                           'peering_router_id': peering_router_id,
                           'exception': e2})
            return Response(_('Failed to create dynamic_peering_connection'), 500)

        return {'dynamic_peering_connection': new_dynamic_peering_connection}
コード例 #24
0
ファイル: volume.py プロジェクト: paperandsoap/tricircle
    def put(self, _id, **kw):
        context = t_context.extract_context_from_environ()

        # TODO(joehuang): Implement API multi-version compatibility
        # currently _convert_header and _convert_object are both dummy
        # functions and API versions are hard coded. After multi-version
        # compatibility is implemented, API versions will be retrieved from
        # top and bottom API server, also, _convert_header and _convert_object
        # will do the real job to convert the request header and body
        # according to the API versions.
        t_release = cons.R_MITAKA
        b_release = cons.R_MITAKA

        s_ctx = self._get_res_routing_ref(context, _id, request.url)
        if not s_ctx:
            return Response(_('Resource not found'), 404)

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

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

        t_vol = kw['volume']

        # add or remove key-value in the request for diff. version
        b_vol_req = self._convert_object(t_release,
                                         b_release,
                                         t_vol,
                                         res_type=cons.RT_VOLUME)

        b_body = jsonutils.dumps({'volume': b_vol_req})

        resp = hclient.forward_req(context, 'PUT', b_headers, s_ctx['b_url'],
                                   b_body)

        b_status = resp.status_code
        b_ret_body = jsonutils.loads(resp.content)
        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 found 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
コード例 #25
0
ファイル: volume.py プロジェクト: paperandsoap/tricircle
    def post(self, **kw):
        context = t_context.extract_context_from_environ()

        if 'volume' not in kw:
            pecan.abort(400, _('Volume not found in request body'))
            return

        if 'availability_zone' not in kw['volume']:
            pecan.abort(400, _('Availability zone not set in request'))
            return

        pod, pod_az = az_ag.get_pod_by_az_tenant(
            context,
            az_name=kw['volume']['availability_zone'],
            tenant_id=self.tenant_id)
        if not pod:
            pecan.abort(500, _('Pod not configured or scheduling failure'))
            LOG.error(_LE("Pod not configured or scheduling failure"))
            return

        t_pod = db_api.get_top_pod(context)
        if not t_pod:
            pecan.abort(500, _('Top Pod not configured'))
            LOG.error(_LE("Top Pod not configured"))
            return

        # TODO(joehuang): get release from pod configuration,
        # to convert the content
        # b_release = pod['release']
        # t_release = t_pod['release']
        t_release = cons.R_MITAKA
        b_release = cons.R_MITAKA

        s_ctx = hclient.get_pod_service_ctx(context,
                                            request.url,
                                            pod['pod_name'],
                                            s_type=cons.ST_CINDER)

        if s_ctx['b_url'] == '':
            pecan.abort(500, _('bottom pod endpoint incorrect'))
            LOG.error(
                _LE("bottom pod endpoint incorrect %s") % pod['pod_name'])
            return

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

        t_vol = kw['volume']

        # add or remove key-value in the request for diff. version
        b_vol_req = self._convert_object(t_release,
                                         b_release,
                                         t_vol,
                                         res_type=cons.RT_VOLUME)

        # convert az to the configured one
        # remove the AZ parameter to bottom request for default one
        b_vol_req['availability_zone'] = pod['pod_az_name']
        if b_vol_req['availability_zone'] == '':
            b_vol_req.pop("availability_zone", None)

        b_body = jsonutils.dumps({'volume': b_vol_req})

        resp = hclient.forward_req(context, 'POST', b_headers, s_ctx['b_url'],
                                   b_body)
        b_status = resp.status_code
        b_ret_body = jsonutils.loads(resp.content)

        # build routing and convert response from the bottom pod
        # for different version.
        response.status = b_status
        if b_status == 202:
            if b_ret_body.get('volume') is not None:
                b_vol_ret = b_ret_body['volume']

                try:
                    with context.session.begin():
                        core.create_resource(
                            context, models.ResourceRouting, {
                                'top_id': b_vol_ret['id'],
                                'bottom_id': b_vol_ret['id'],
                                'pod_id': pod['pod_id'],
                                'project_id': self.tenant_id,
                                'resource_type': cons.RT_VOLUME
                            })
                except Exception as e:
                    LOG.exception(
                        _LE('Failed to create volume '
                            'resource routing'
                            'top_id: %(top_id)s ,'
                            'bottom_id: %(bottom_id)s ,'
                            'pod_id: %(pod_id)s ,'
                            '%(exception)s '), {
                                'top_id': b_vol_ret['id'],
                                'bottom_id': b_vol_ret['id'],
                                'pod_id': pod['pod_id'],
                                'exception': e
                            })
                    return Response(
                        _('Failed to create volume '
                          'resource routing'), 500)

                ret_vol = self._convert_object(b_release,
                                               t_release,
                                               b_vol_ret,
                                               res_type=cons.RT_VOLUME)

                ret_vol['availability_zone'] = pod['az_name']

                return {'volume': ret_vol}

        return {'error': b_ret_body}
コード例 #26
0
 def make_response():
     res = Response(content_type='text/event-stream',
                    app_iter=format(get_listener().generator()))
     return res
コード例 #27
0
ファイル: quota_sets.py プロジェクト: zwxhnu/trio2o
 def get_one(self, show_what):
     kw = {}
     if show_what == 'defaults' or show_what == 'detail':
         return self._quota_action(show_what, **kw)
     else:
         return Response(_('Only show defaults or detail allowed'), 400)