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

Python models.RequisicaoVips类代码示例

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

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



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

示例1: dissociate_environment_and_delete

    def dissociate_environment_and_delete(self, authenticated_user, environment_id=None):
        from networkapi.requisicaovips.models import RequisicaoVips
        try:
            healthcheckexpects = HealthcheckExpect.objects.all()
            if (environment_id is not None):
                hces = healthcheckexpects.filter(ambiente__id=environment_id)
                for hce in hces:
                    vip_criado = False
                    for req_vip in RequisicaoVips.get_by_healthcheck_expect(hce.id):
                        if req_vip.vip_criado:
                            vip_criado = True

                    # If any RequsicaoVips associated, dissociate healthcheck
                    # expect from Ambiente
                    if vip_criado:
                        hce.ambiente = None
                        hce.save(authenticated_user)
                    # Else, delete HealthcheckExpect object
                    else:
                        hce.delete()

        except Exception, e:
            self.log.error(u'Falha ao desassociar os healthcheck_expects.')
            raise HealthcheckExpectError(
                e, u'Falha ao desassociar os healthcheck_expects.')
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:25,代码来源:models.py


示例2: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """
        Handles GET requests to list all the VIPs.

        URL: vip/all/
        """

        try:
            if not has_perm(user,
                            AdminPermission.VIPS_REQUEST,
                            AdminPermission.READ_OPERATION):
                return self.not_authorized()

            request_vips = RequisicaoVips.get_all()
            vips = {}

            for vip in request_vips:
                request_vip_map = vip.variables_to_map()
                request_vip_map['id'] = vip.id
                request_vip_map['validado'] = vip.validado
                request_vip_map['vip_criado'] = vip.vip_criado
                request_vip_map['id_ip'] = vip.ip_id
                request_vip_map['id_ipv6'] = vip.ipv6_id
                request_vip_map[
                    'id_healthcheck_expect'] = vip.healthcheck_expect_id
                vips['vip_%s' % (vip.id)] = request_vip_map

            return self.response(dumps_networkapi(vips))

        except (RequisicaoVipsNotFoundError):
            return self.response_error(152)
        except (RequisicaoVipsError, GrupoError):
            return self.response_error(1)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:33,代码来源:RequestAllVipsResource.py


示例3: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Trata as requisições de GET para listar uma requisição de VIP.

        Filtra a requisição de VIP por chave primária.

        URL: vip/id_vip
        """

        try:
            if kwargs.get('id_vip') is None:
                return super(RequisicaoVipsResource, self).handle_get(request, user, *args, **kwargs)

            if not has_perm(user,
                            AdminPermission.VIPS_REQUEST,
                            AdminPermission.READ_OPERATION):
                return self.not_authorized()

            # Valid Ip ID
            if not is_valid_int_greater_zero_param(kwargs.get('id_vip')):
                self.log.error(
                    u'The id_vip parameter is not a valid value: %s.', kwargs.get('id_vip'))
                raise InvalidValueError(None, 'id_vip', kwargs.get('id_vip'))

            request_vip = RequisicaoVips.get_by_pk(kwargs.get('id_vip'))

            request_vip_map = request_vip.variables_to_map()

            """"""
            vip_port_list, reals_list, reals_priority, reals_weight = request_vip.get_vips_and_reals(
                request_vip.id)

            if reals_list:
                request_vip_map['reals'] = {'real': reals_list}
                request_vip_map['reals_prioritys'] = {
                    'reals_priority': reals_priority}
                request_vip_map['reals_weights'] = {
                    'reals_weight': reals_weight}

            request_vip_map['portas_servicos'] = {'porta': vip_port_list}

            """"""

            request_vip_map['id'] = request_vip.id
            request_vip_map['validado'] = convert_boolean_to_int(
                request_vip.validado)
            request_vip_map['vip_criado'] = convert_boolean_to_int(
                request_vip.vip_criado)
            request_vip_map['id_ip'] = request_vip.ip_id
            request_vip_map['id_ipv6'] = request_vip.ipv6_id
            request_vip_map[
                'id_healthcheck_expect'] = request_vip.healthcheck_expect_id
            request_vip_map['l7_filter'] = request_vip.l7_filter
            request_vip_map['rule_id'] = request_vip.rule_id

            return self.response(dumps_networkapi({'vip': request_vip_map}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:58,代码来源:RequisicaoVipsResource.py


示例4: is_ipv6_in_use

    def is_ipv6_in_use(self, ipv6, vip_id):

        is_in_use = True
        pool_member_count = ServerPoolMember.objects.filter(ipv6=ipv6).exclude(
            server_pool__vipporttopool__requisicao_vip__ipv6=vip_id).count()
        vip_count = RequisicaoVips.get_by_ipv6_id(
            ipv6.id).exclude(pk=vip_id).count()
        if vip_count == 0 and pool_member_count == 0:
            is_in_use = False

        return is_in_use
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:11,代码来源:RequisicaoVipDeleteResource.py


示例5: handle_delete

    def handle_delete(self, request, user, *args, **kwargs):
        """
        Treat DELETE requests to remove a vip request.
        Also remove reals related and balancer ips (if this ips isn't used for another vip).

        URL: vip/delete/<id_vip>/
        """

        try:
            vip_id = kwargs.get('id_vip')
            keep_ip = bool(request.REQUEST.get('keep_ip', False))

            # User permission
            if not has_perm(user, AdminPermission.VIPS_REQUEST, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Valid vip ID
            if not is_valid_int_greater_zero_param(vip_id):
                self.log.error(
                    u'Parameter id_vip is invalid. Value: %s.', vip_id)
                raise InvalidValueError(None, 'id_vip', vip_id)

            vip = RequisicaoVips.get_by_pk(vip_id)

            if vip.vip_criado:
                return self.response_error(370, vip_id)

            ipv4 = vip.ip
            ipv6 = vip.ipv6

            with distributedlock(LOCK_VIP % vip_id):
                try:
                    vip.delete_vips_and_reals(user)

                    vip.remove(user, vip_id)

                    # SYNC_VIP
                    delete_new(vip_id)

                    if ipv4 and not keep_ip:
                        if not self.is_ipv4_in_use(ipv4, vip_id):
                            ipv4.delete()
                    if ipv6 and not keep_ip:
                        if not self.is_ipv6_in_use(ipv6, vip_id):
                            ipv6.delete()
                except IpCantRemoveFromServerPool, e:
                    raise e
                except IpCantBeRemovedFromVip, e:
                    raise e
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:51,代码来源:RequisicaoVipDeleteResource.py


示例6: handle_put

    def handle_put(self, request, user, *args, **kwargs):
        """ Handles a PUT request to edit the L7 filter.

        URL: vip/<id_vip>/filter/
        """

        if not has_perm(user,
                        AdminPermission.VIP_ALTER_SCRIPT,
                        AdminPermission.WRITE_OPERATION):
            return self.not_authorized()

        id_vip = kwargs.get('id_vip')

        # Load XML data
        xml_map, attrs_map = loads(request.raw_post_data)

        # XML data format
        networkapi_map = xml_map.get('networkapi')
        if networkapi_map is None:
            return self.response_error(3, u'There is no value to the networkapi tag of XML request.')
        vip_map = networkapi_map.get('vip')
        if vip_map is None:
            return self.response_error(3, u'There is no value to the vip tag of XML request.')

        vip = RequisicaoVips.get_by_pk(id_vip)

        # Get XML data
        l7_filter = vip_map['l7_filter']

        vip.l7_filter = l7_filter
        vip.filter_valid = False

        # If the l7_filter is a rule, set filter_valid to TRUE
        if vip_map.get('rule_id') is not None:
            vip.filter_valid = 1
            rule = Rule.objects.get(pk=vip_map.get('rule_id'))
            vip.l7_filter = '\n'.join(
                rule.rulecontent_set.all().values_list('content', flat=True))
            vip.rule = rule
        else:
            vip.filter_valid = 0
            vip.rule = None

        vip.save(user)

        map = dict()
        map['sucesso'] = 'sucesso'
        return self.response(dumps_networkapi(map))
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:48,代码来源:RequestVipL7Resource.py


示例7: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles get requests to validate Vip Requests by id.

        URLs: /vip/validate/<id_vip>/
        """

        self.log.info('Validate Vip Request by id')

        try:
            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.VIP_VALIDATION, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Business Validations

            id_vip = kwargs.get('id_vip')

            # Valid vip id
            if not is_valid_int_greater_zero_param(id_vip):
                self.log.error(
                    u'Parameter id_vip is invalid. Value: %s.', id_vip)
                raise InvalidValueError(None, 'id_vip', id_vip)

            vip = RequisicaoVips.get_by_pk(id_vip)

            with distributedlock(LOCK_VIP % id_vip):
                vip.validado = True
                vip.save()

            return self.response(dumps_networkapi({}))

        except RequisicaoVipsNotFoundError:
            return self.response_error(152)
        except RequisicaoVipsError:
            return self.response_error(150, 'Failed to validate vip request.')
        except InvalidValueError, e:
            self.log.error(
                u'Parameter %s is invalid. Value: %s.', e.param, e.value)
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:43,代码来源:RequestVipValidateResource.py


示例8: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Validate L7 filter

        URLs: /vip/l7/<id_vip>/validate/
        """
        try:

            if not has_perm(user,
                            AdminPermission.VIP_VALIDATION,
                            AdminPermission.WRITE_OPERATION):
                return self.not_authorized()

            self.log.info('Validate L7 filter to VIP')

            id_vip = kwargs.get('id_vip')

            # Valid Vip ID
            if not is_valid_int_greater_zero_param(id_vip):
                self.log.error(
                    u'The vip_id parameter is not a valid value: %s.', id_vip)
                raise InvalidValueError(None)

            vip = RequisicaoVips.get_by_pk(id_vip)

            with distributedlock(LOCK_VIP % id_vip):

                # Vip must be created
                if not vip.vip_criado:
                    self.log.error(
                        u'L7 filter can not be changed because VIP has not yet been created.')
                    raise RequestVipsNotBeenCreatedError(None)

                vip.filter_valid = True

                vip.save()

                map = dict()
                map['sucesso'] = 'sucesso'
                return self.response(dumps_networkapi(map))

        except UserNotAuthorizedError:
            return self.not_authorized()
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:42,代码来源:RequestVipL7ValidateResource.py


示例9: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles a GET request to return L7 data

        URL: vip/l7/<id_vip>/
        """

        try:
            if not has_perm(user,
                            AdminPermission.VIPS_REQUEST,
                            AdminPermission.READ_OPERATION):
                return self.not_authorized()

            # Valid Ip ID
            if not is_valid_int_greater_zero_param(kwargs.get('id_vip')):
                self.log.error(
                    u'The id_vip parameter is not a valid value: %s.', kwargs.get('id_vip'))
                raise InvalidValueError(None, 'id_vip', kwargs.get('id_vip'))

            request_vip = RequisicaoVips.get_by_pk(kwargs.get('id_vip'))

            date = request_vip.applied_l7_datetime

            if date:
                date = date.strftime('%d/%m/%Y %H:%M:%S')

            request_vip_map = dict()
            request_vip_map['l7_filter'] = request_vip.l7_filter
            request_vip_map['rule'] = request_vip.rule
            request_vip_map['filter_applied'] = request_vip.filter_applied
            request_vip_map['rule_applied'] = request_vip.rule_applied
            request_vip_map['filter_rollback'] = request_vip.filter_rollback
            request_vip_map['rule_rollback'] = request_vip.rule_rollback
            request_vip_map['applied_l7_datetime'] = date
            request_vip_map['filter_valid'] = convert_boolean_to_int(
                request_vip.filter_valid)

            return self.response(dumps_networkapi({'vip': request_vip_map}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:40,代码来源:RequestVipL7Resource.py


示例10: __post_virtual_group_vip


#.........这里部分代码省略.........
                else:
                    reals_priority_map = ['0' for __real in real_maps]

                vip_map['reals_prioritys'] = {
                    'reals_priority': reals_priority_map}

                reals_weight_map = vip_map.get('reals_weights')
                if reals_weight_map is not None:
                    reals_weight_map = reals_weight_map.get('reals_weight')
                    if reals_weight_map is None:
                        reals_weight_map = ['0' for __real in real_maps]
                else:
                    reals_weight_map = ['0' for __real in real_maps]

                vip_map['reals_weights'] = {'reals_weight': reals_weight_map}

                # Valid real names and real ips of real server
                if vip_map.get('reals') is not None:

                    evip = EnvironmentVip.get_by_values(
                        vip_map.get('finalidade'), vip_map.get('cliente'), vip_map.get('ambiente'))

                    for real in vip_map.get('reals').get('real'):
                        ip_aux_error = real.get('real_ip')
                        equip_id = real.get('real_name')
                        if equip_id is not None:
                            equip = Equipamento.get_by_name(equip_id)
                        else:
                            self.log.error(
                                u'The real_name parameter is not a valid value: None.')
                            raise InvalidValueError(None, 'real_name', 'None')

                        # Valid Real
                        RequisicaoVips.valid_real_server(
                            ip_aux_error, equip, evip, False)

                        vip_map, code = RequisicaoVips().valid_values_reals_priority(
                            vip_map)
                        if code is not None:
                            return self.response_error(code)

                        vip_map, code = RequisicaoVips().valid_values_reals_weight(
                            vip_map)
                        if code is not None:
                            return self.response_error(code)

                # Insere ou atualiza a requisição de VIP
                if (id_vip_request_map is not None):

                    resp_vip_map['requisicao_vip'] = id_vip_request_map

                    if not is_valid_int_greater_zero_param(id_vip_request_map.get('id')):
                        self.log.error(
                            u'The requisicao_vip.id parameter is not a valid value: %s.', id_vip_request_map.get('id'))
                        raise InvalidValueError(
                            None, 'requisicao_vip.id', id_vip_request_map.get('id'))

                    vip_request = RequisicaoVips.get_by_pk(
                        id_vip_request_map.get('id'))

                    vip_map['id_ip'] = vip_request.ip_id
                    if vip_request.validado:
                        vip_map['validado'] = '1'
                    else:
                        vip_map['validado'] = '0'
                    if vip_request.vip_criado:
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:67,代码来源:GrupoVirtualResource.py


示例11: handle_post

    def handle_post(self, request, user, *args, **kwargs):
        """Treat requests POST to insert request VIP.

        URLs: /requestvip/

        deprecated:: Use the new rest API
        """

        self.log.info("Add request VIP")

        try:
            # Load XML data
            xml_map, attrs_map = loads(
                request.raw_post_data, ['real', 'reals_weight', 'reals_priority', 'porta'])

            # XML data format

            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            vip_map = networkapi_map.get('vip')
            if vip_map is None:
                return self.response_error(3, u'There is no value to the vip tag  of XML request.')

            # User permission
            if not has_perm(user, AdminPermission.VIPS_REQUEST, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Valid Ipv4 and Ipv6 ID
            if (vip_map.get('id_ipv4') is None and vip_map.get('id_ipv6') is None):
                self.log.error(
                    u'The id_ipv4 and id_ipv6 parameter is not a valid value: %s.', vip_map.get('id_ipv4'))
                raise InvalidValueError(
                    None, 'id_ipv4 e id_vip6', vip_map.get('id_ipv4'))

            if (vip_map.get('id_ipv4') != None):
                if not is_valid_int_greater_zero_param(vip_map.get('id_ipv4')):
                    self.log.error(
                        u'The id_ipv4 parameter is not a valid value: %s.', vip_map.get('id_ipv4'))
                    raise InvalidValueError(
                        None, 'id_ipv4', vip_map.get('id_ipv4'))

            if (vip_map.get('id_ipv6') != None):
                if not is_valid_int_greater_zero_param(vip_map.get('id_ipv6')):
                    self.log.error(
                        u'The id_ipv6 parameter is not a valid value: %s.', vip_map.get('id_ipv6'))
                    raise InvalidValueError(
                        None, 'id_ipv6', vip_map.get('id_ipv6'))

            # Valid maxcon
            if not is_valid_int_greater_equal_zero_param(vip_map.get('maxcon')):
                self.log.error(
                    u'The maxcon parameter is not a valid value: %s.', vip_map.get('maxcon'))
                raise InvalidValueError(None, 'maxcon', vip_map.get('maxcon'))

            vip = RequisicaoVips()

            finalidade = vip_map.get('finalidade')
            cliente = vip_map.get('cliente')
            ambiente = vip_map.get('ambiente')

            try:
                evip = EnvironmentVip.get_by_values(
                    finalidade, cliente, ambiente)
            except Exception, e:
                raise EnvironmentVipNotFoundError(
                    e, 'The fields finality or client or ambiente is None')

            # Valid real names and real ips of real server
            if vip_map.get('reals') is not None:

                for real in vip_map.get('reals').get('real'):
                    ip_aux_error = real.get('real_ip')
                    equip_aux_error = real.get('real_name')
                    if equip_aux_error is not None:
                        equip = Equipamento.get_by_name(equip_aux_error)
                    else:
                        self.log.error(
                            u'The real_name parameter is not a valid value: None.')
                        raise InvalidValueError(None, 'real_name', 'None')

                    # Valid Real
                    RequisicaoVips.valid_real_server(
                        ip_aux_error, equip, evip, False)

                # Valid reals_prioritys
                vip_map, code = vip.valid_values_reals_priority(vip_map)
                if code is not None:
                    return self.response_error(code)

                # Valid reals_weight
                vip_map, code = vip.valid_values_reals_weight(vip_map)
                if code is not None:
                    return self.response_error(code)

            # Existing IPv4 ID
            if vip_map.get('id_ipv4') is not None:
#.........这里部分代码省略.........
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:101,代码来源:RequestVipsResource.py


示例12: handle_put

    def handle_put(self, request, user, *args, **kwargs):
        """Treat requests PUT change request VIP.

        URLs: /requestvip/<id_vip>/

        deprecated:: Use the new rest API
        """

        self.log.info("Change request VIP")

        try:

            vip_id = kwargs.get('id_vip')

            # Load XML data
            xml_map, attrs_map = loads(
                request.raw_post_data, ['real', 'reals_weight', 'reals_priority', 'porta'])

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            vip_map = networkapi_map.get('vip')
            if vip_map is None:
                return self.response_error(3, u'There is no value to the vip tag  of XML request.')

            # User permission
            if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Valid Vip ID
            if not is_valid_int_greater_zero_param(vip_id):
                self.log.error(
                    u'The vip_id parameter is not a valid value: %s.', vip_id)
                raise InvalidValueError(None, 'vip_id', vip_id)

            # Valid Ipv4 and Ipv6 ID
            if (vip_map.get('id_ipv4') is None and vip_map.get('id_ipv6') is None):
                self.log.error(
                    u'The id_ipv4 and id_ipv6 parameter is not a valid value: %s.', vip_map.get('id_ipv4'))
                raise InvalidValueError(
                    None, 'id_ipv4 e id_vip6', vip_map.get('id_ipv4'))

            if (vip_map.get('id_ipv4') != None):
                if not is_valid_int_greater_zero_param(vip_map.get('id_ipv4')):
                    self.log.error(
                        u'The id_ipv4 parameter is not a valid value: %s.', vip_map.get('id_ipv4'))
                    raise InvalidValueError(
                        None, 'id_ipv4', vip_map.get('id_ipv4'))

            if (vip_map.get('id_ipv6') != None):
                if not is_valid_int_greater_zero_param(vip_map.get('id_ipv6')):
                    self.log.error(
                        u'The id_ipv6 parameter is not a valid value: %s.', vip_map.get('id_ipv6'))
                    raise InvalidValueError(
                        None, 'id_ipv6', vip_map.get('id_ipv6'))

            # Valid Vip validated
            if not is_valid_boolean_param(vip_map.get('validado')):
                self.log.error(
                    u'The validated parameter is not a valid value: %s.', vip_map.get('validado'))
                raise InvalidValueError(
                    None, 'validated', vip_map.get('validado'))

            # Valid Vip vip_created
            if not is_valid_boolean_param(vip_map.get('vip_criado')):
                self.log.error(
                    u'The vip_created parameter is not a valid value: %s.', vip_map.get('vip_criado'))
                raise InvalidValueError(
                    None, 'vip_created', vip_map.get('vip_criado'))

            # Valid maxcon
            if not is_valid_int_greater_equal_zero_param(vip_map.get('maxcon')):
                self.log.error(
                    u'The maxcon parameter is not a valid value: %s.', vip_map.get('maxcon'))
                raise InvalidValueError(None, 'maxcon', vip_map.get('maxcon'))

            # Existing Vip ID
            vip = RequisicaoVips.get_by_pk(vip_id)

            with distributedlock(LOCK_VIP % vip_id):

                # Valid Vip created
                if vip.vip_criado:
                    self.log.error(
                        u'The IP of the request for VIP %d can not be changed because the VIP is already created.' % vip.id)
                    raise RequisicaoVipsAlreadyCreatedError(None)

                # Get variables
                variables_map = vip.variables_to_map()

                # Valid variables
                vip.set_variables(variables_map)

                evip = EnvironmentVip.get_by_values(variables_map.get(
                    'finalidade'), variables_map.get('cliente'), variables_map.get('ambiente'))

#.........这里部分代码省略.........
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:101,代码来源:RequestVipsResource.py


示例13: insert_vip_request

def insert_vip_request(vip_map, user):
    '''Insere uma requisição de VIP.

    @param vip_map: Mapa com os dados da requisição.
    @param user: Usuário autenticado.

    @return: Em caso de sucesso: tupla (0, <requisição de VIP>).
             Em caso de erro: tupla (código da mensagem de erro, argumento01, argumento02, ...)

    @raise IpNotFoundError: IP não cadastrado.

    @raise IpError: Falha ao pesquisar o IP.

    @raise HealthcheckExpectNotFoundError: HealthcheckExpect não cadastrado.

    @raise HealthcheckExpectError: Falha ao pesquisar o HealthcheckExpect.

    @raise InvalidFinalidadeValueError: Finalidade com valor inválido.

    @raise InvalidClienteValueError: Cliente com valor inválido.

    @raise InvalidAmbienteValueError: Ambiente com valor inválido.

    @raise InvalidCacheValueError: Cache com valor inválido.

    @raise InvalidMetodoBalValueError: Valor do método de balanceamento inválido.

    @raise InvalidPersistenciaValueError: Persistencia com valor inválido.

    @raise InvalidHealthcheckTypeValueError: Healthcheck_Type com valor inválido ou inconsistente em relação ao valor do healthcheck_expect.

    @raise InvalidTimeoutValueError: Timeout com valor inválido.

    @raise InvalidHostNameError: Host não cadastrado.

    @raise EquipamentoError: Falha ao pesquisar o equipamento.

    @raise InvalidMaxConValueError: Número máximo de conexões com valor inválido.

    @raise InvalidBalAtivoValueError: Bal_Ativo com valor inválido.

    @raise InvalidTransbordoValueError: Transbordo com valor inválido.

    @raise InvalidServicePortValueError: Porta do Serviço com valor inválido.

    @raise InvalidRealValueError: Valor inválido de um real.

    @raise InvalidHealthcheckValueError: Valor do healthcheck inconsistente em relação ao valor do healthcheck_type.

    @raise RequisicaoVipsError: Falha ao inserir a requisição de VIP.

    @raise UserNotAuthorizedError:
    '''

    log = Log('insert_vip_request')

    if not has_perm(user, AdminPermission.VIPS_REQUEST, AdminPermission.WRITE_OPERATION):
        raise UserNotAuthorizedError(
            None, u'Usuário não tem permissão para executar a operação.')

    ip_id = vip_map.get('id_ip')
    if not is_valid_int_greater_zero_param(ip_id):
        log.error(u'The ip_id parameter is not a valid value: %s.', ip_id)
        raise InvalidValueError(None, 'ip_id', ip_id)
    else:
        ip_id = int(ip_id)

    vip = RequisicaoVips()
    vip.ip = Ip()
    vip.ip.id = ip_id

    # Valid ports
    vip_map, code = vip.valid_values_ports(vip_map)
    if code is not None:
        return code, vip

    # get environmentVip dor validation dynamic heathcheck

    finalidade = vip_map.get('finalidade')
    cliente = vip_map.get('cliente')
    ambiente = vip_map.get('ambiente')

    if not is_valid_string_minsize(finalidade, 3) or not is_valid_string_maxsize(finalidade, 50):
        log.error(u'Finality value is invalid: %s.', finalidade)
        raise InvalidValueError(None, 'finalidade', finalidade)

    if not is_valid_string_minsize(cliente, 3) or not is_valid_string_maxsize(cliente, 50):
        log.error(u'Client value is invalid: %s.', cliente)
        raise InvalidValueError(None, 'cliente', cliente)

    if not is_valid_string_minsize(ambiente, 3) or not is_valid_string_maxsize(ambiente, 50):
        log.error(u'Environment value is invalid: %s.', ambiente)
        raise InvalidValueError(None, 'ambiente', ambiente)

    try:
        environment_vip = EnvironmentVip.get_by_values(
            finalidade, cliente, ambiente)
    except Exception, e:
        raise EnvironmentVipNotFoundError(
            e, 'The fields finality or client or ambiente is None')
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:100,代码来源:RequisicaoVipsResource.py


示例14: handle_post

    def handle_post(self, request, user, *args, **kwargs):
        '''Treat POST requests to run remove script for vip

        URL: vip/remove/
        '''

        try:

            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.VIP_REMOVE_SCRIPT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Business Validations

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                msg = u'There is no value to the networkapi tag of XML request.'
                self.log.error(msg)
                return self.response_error(3, msg)
            vip_map = networkapi_map.get('vip')
            if vip_map is None:
                msg = u'There is no value to the vlan tag of XML request.'
                self.log.error(msg)
                return self.response_error(3, msg)

            # Get XML data
            vip_id = vip_map.get('id_vip')

            # Valid vip ID
            if not is_valid_int_greater_zero_param(vip_id):
                self.log.error(
                    u'Parameter id_vip is invalid. Value: %s.', vip_id)
                raise InvalidValueError(None, 'id_vip', vip_id)

            # Vip must exists in database
            vip = RequisicaoVips.get_by_pk(vip_id)

            with distributedlock(LOCK_VIP % vip_id):

                # Equipment permissions
                if vip.ip is not None:
                    for ip_equipment in vip.ip.ipequipamento_set.all():
                        if not has_perm(user, AdminPermission.VIP_CREATE_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
                            return self.not_authorized()

                if vip.ipv6 is not None:
                    for ip_equipment in vip.ipv6.ipv6equipament_set.all():
                        if not has_perm(user, AdminPermission.VIP_CREATE_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
                            return self.not_authorized()

                # Must be validated
                if not vip.validado:
                    return self.response_error(191, vip_id)

                # Must be created
                if not vip.vip_criado:
                    return self.response_error(322, vip_id)

                # Business Rules

                # Make command
                command = VIP_REMOVE % (vip.id)

                # Execute command
                code, stdout, stderr = exec_script(command)
                if code == 0:

                    success_map = dict()
                    success_map['codigo'] = '%04d' % code
                    success_map['descricao'] = {
                        'stdout': stdout, 'stderr': stderr}

                    vip.vip_criado = 0
                    vip.save()

                    #Marks the server pool as not created if the
                    # server pool is not used in another already created vip request
                    server_pools = ServerPool.objects.filter(vipporttopool__requisicao_vip=vip.id)

                    for server_pool in server_pools:
                        #Checks if server pool is still used in another created vip request
                        server_pools_still_used = VipPortToPool.objects.filter(server_pool=server_pool).exclude(requisicao_vip=vip.id)
                        vip_with_server_pool_is_created = 0
                        for server_pool_still_used in server_pools_still_used:
                            if server_pool_still_used.requisicao_vip.vip_criado:
                                vip_with_server_pool_is_created = 1 

                        if not vip_with_server_pool_is_created and server_pool.pool_created:
                            server_pool.pool_created = 0
                            server_pool.save()

                        map = dict()
#.........这里部分代码省略.........
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:101,代码来源:RemoveVipResource.py


示例15: handle_post

    def handle_post(self, request, user, *args, **kwargs):
        """Handles POST requests to valid Real server.

        URL: vip/real/valid/
        """
        self.log.info('Valid Real Server')

        try:

            # Business Validations

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            real_map = networkapi_map.get('real')
            if real_map is None:
                return self.response_error(3, u'There is no value to the vip tag  of XML request.')

            # Get XML data
            ip = real_map.get('ip')
            name = real_map.get('name_equipment')
            id_evip = real_map.get('id_environment_vip')
            valid = real_map.get('valid')

            # User permission
            if not has_perm(user, AdminPermission.VIPS_REQUEST, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Valid IP
            if not is_valid_ip_ipaddr(ip):
                self.log.error(u'Parameter ip is invalid. Value: %s.', ip)
                raise InvalidValueError(None, 'ip', ip)

            # Valid Name Equipment
            if not is_valid_string_minsize(name, 3) or not is_valid_string_maxsize(name, 80) or not is_valid_regex(name, '^[A-Z0-9-_]+$'):
                self.log.error(
                    u'Parameter name_equipment is invalid. Value: %s', name)
                raise InvalidValueError(None, 'name_equipment', name)

            # Valid Environment Vip
            if not is_valid_int_greater_zero_param(id_evip):
                self.log.error(
                    u'Parameter id_environment_vip is invalid. Value: %s.', id_evip)
                raise InvalidValueError(None, 'id_environment_vip', id_evip)

            # Valid Equipment
            equip = Equipamento.get_by_name(name)

            # Valid EnvironmentVip
            evip = EnvironmentVip.get_by_pk(id_evip)

            version = ''
            if is_valid_ipv4(ip):
                version = IP_VERSION.IPv4[1]

            elif is_valid_ipv6(ip):
                version = IP_VERSION.IPv6[1]

            ip, equip, evip = RequisicaoVips.valid_real_server(
                ip, equip, evip, valid)

            real_dict = {}
            ip_dict = model_to_dict(ip)
            ip_dict['version'] = version

            real_dict['ip'] = ip_dict
            real_dict['equipment'] = model_to_dict(equip)
            real_dict['environmentvip'] = model_to_dict(evip)

            return self.response(dumps_networkapi({'real': real_dict}))

        except XMLError, x:
            self.log.error(u'Error reading the XML request.')
            return self.response_error(3, x)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:81,代码来源:RequestVipRealValidResource.py


示例16: handle_put

    def handle_put(self, request, user, *args, **kwargs):
        """Treat  requests PUT change limit connections to VIP.

        URLs: /vip/<id_vip>/maxcon/<maxcon>/
        """

        self.log.info("Change limit connections to VIP")

        try:

            vip_id = kwargs.get('id_vip')
            maxcon = kwargs.get('maxcon')

            # User permission
            if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Valid Vip ID
            if not is_valid_int_greater_zero_param(vip_id):
                self.log.error(
                    u'The vip_id parameter is not a valid value: %s.', vip_id)
                raise InvalidValueError(None)

            # Valid Maxcon
            if not is_valid_int_greater_equal_zero_param(maxcon):
                self.log.error(
                    u'The maxcon parameter is not a valid value: %s.', maxcon)
                raise InvalidValueError(None)

            # Existing Vip ID
            vip = RequisicaoVips.get_by_pk(vip_id)

            with distributedlock(LOCK_VIP % vip_id):

                vip_old = clone(vip)
                server_pools = ServerPool.objects.filter(vipporttopool__requisicao_vip=vip)
                server_pools_old = []
                server_pools_members_old = []
                for sp in server_pools:
                    server_pools_old.append(sp)
                    for spm in sp.serverpoolmember_set.all():
                        server_pools_members_old.append(spm)

                # Vip must be created
                if not vip.vip_criado:
                    self.log.error(
                        u'Maxcon can not be changed because VIP has not yet been created.')
                    raise RequestVipsNotBeenCreatedError(None)

                # Vip equipments permission
                if vip.ip is not None:
                    for ip_equipment in vip.ip.ipequipamento_set.all():
                        if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
                            self.log.error(
                                u'Groups of equipment registered with the IP of the  VIP request  is not allowed of acess.')
                            raise EquipmentGroupsNotAuthorizedError(None)

                if vip.ipv6 is not None:
                    for ip_equipment in vip.ipv6.ipv6equipament_set.all():
                        if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
                            self.log.error(
                                u'Groups of equipment registered with the IP of the  VIP request  is not allowed of acess.')
                            raise EquipmentGroupsNotAuthorizedError(None)

                # Get variables
                variables_map = vip.variables_to_map()

                # Valid variables
                vip.set_variables(variables_map)

                # Valid real names and real ips of real server
                if variables_map.get('reals') is not None:

                    evip = EnvironmentVip.get_by_values(variables_map.get(
                        'finalidade'), variables_map.get('cliente'), variables_map.get('ambiente'))

                    for real in variables_map.get('reals').get('real'):
                        ip_aux_error = real.get('real_ip')
                        equip_aux_error = real.get('real_name')
                        equip = Equipamento.get_by_name(equip_aux_error)

                        # Valid Real
                        RequisicaoVips.valid_real_server(
                            ip_aux_error, equip, evip)

                    # Valid reals_prioritys
                    variables_map, code = vip.valid_values_reals_priority(
                        variables_map)
                    if code is not None:
                        return self.response_error(329)

                    # Valid reals_weight
                    variables_map, code = vip.valid_values_reals_weight(
                        variables_map)
                    if code is not None:
                        return self.response_error(330)

                    # Valid ports
#.........这里部分代码省略.........
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:101,代码来源:RequestMaxconResource.py


示例17: new_to_old

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python settings.SPECS类代码示例发布时间:2022-05-27
下一篇:
Python factory.PluginFactory类代码示例发布时间: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