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


Python RequisicaoVips.validado方法代码示例

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


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

示例1: handle_post

# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import validado [as 别名]

#.........这里部分代码省略.........
                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:
                vip.ip = Ip().get_by_pk(vip_map.get('id_ipv4'))

            # Existing IPv6 ID
            if vip_map.get('id_ipv6') is not None:
                vip.ipv6 = Ipv6().get_by_pk(vip_map.get('id_ipv6'))

            # Valid ports
            vip_map, code = vip.valid_values_ports(vip_map)
            if code is not None:
                return self.response_error(code[0], code[1])

            # Valid HealthcheckExpect
            vip_map, vip, code = vip.valid_values_healthcheck(
                vip_map, vip, evip)
            if code is not None:
                return self.response_error(code)

            # Host
            host_name = vip_map.get('host')
            if not is_valid_string_minsize(host_name, 3) or not is_valid_string_maxsize(host_name, 100):
                self.log.error(u'Host_name value is invalid: %s.', host_name)
                raise InvalidValueError(None, 'host_name', host_name)

            # Areanegocio
            areanegocio = vip_map.get('areanegocio')
            if not is_valid_string_minsize(areanegocio, 3) or not is_valid_string_maxsize(areanegocio, 100):
                self.log.error(
                    u'Areanegocio value is invalid: %s.', areanegocio)
                raise InvalidValueError(None, 'areanegocio', areanegocio)

            # Nome_servico
            nome_servico = vip_map.get('nome_servico')
            if not is_valid_string_minsize(nome_servico, 3) or not is_valid_string_maxsize(nome_servico, 100):
                self.log.error(
                    u'Nome_servico value is invalid: %s.', nome_servico)
                raise InvalidValueError(None, 'nome_servico', nome_servico)

            # Existing l7_filter
            if vip_map.get('l7_filter') is not None:
                vip.l7_filter = vip_map.get('l7_filter')

            # If the l7_filter is a rule
            if vip_map.get('rule_id') is not None:
                if not is_valid_int_greater_zero_param(vip_map.get('rule_id')):
                    self.log.error(
                        u'The rule_id parameter is not a valid value: %s.', vip_map.get('rule_id'))
                    raise InvalidValueError(
                        None, 'rule_id', vip_map.get('rule_id'))

                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

            # set variables
            vip.filter_valid = 1
            vip.validado = 0
            vip.vip_criado = 0
            vip.set_variables(vip_map)

            try:
                # save Resquest Vip
                vip.save()

                # save VipPortToPool, ServerPool and ServerPoolMember
                vip.save_vips_and_ports(vip_map, user)

            except Exception, e:
                if isinstance(e, IntegrityError):
                    # Duplicate value for Port Vip, Port Real and IP
                    self.log.error(u'Failed to save the request vip.')
                    return self.response_error(353)
                else:
                    raise e
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:104,代码来源:RequestVipsResource.py

示例2: new_to_old

# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import validado [as 别名]
def new_to_old(vp):

    from networkapi.api_vip_request.models import VipRequestDSCP
    from networkapi.requisicaovips.models import DsrL3_to_Vip, \
        RequisicaoVips, VipPortToPool

    try:
        vip_map = dict()
        vip = RequisicaoVips()
        vip.id = vp.id
        vip.ip = vp.ipv4 if vp.ipv4 else None
        vip.ipv6 = vp.ipv6 if vp.ipv6 else None
        vip_map['ip'] = vp.ipv4 if vp.ipv4 else None
        vip_map['ipv6'] = vp.ipv6 if vp.ipv6 else None
        vip_map['finalidade'] = vp.environmentvip.finalidade_txt
        vip_map['cliente'] = vp.environmentvip.cliente_txt
        vip_map['ambiente'] = vp.environmentvip.ambiente_p44_txt
        for vp_optionvip in vp.viprequestoptionvip_set.all():
            if vp_optionvip.optionvip.tipo_opcao == u'Persistencia':
                vip_map['persistencia'] = vp_optionvip.optionvip.nome_opcao_txt
            if vp_optionvip.optionvip.tipo_opcao == u'timeout':
                vip_map['timeout'] = vp_optionvip.optionvip.nome_opcao_txt
            if vp_optionvip.optionvip.tipo_opcao == u'cache':
                vip_map['cache'] = vp_optionvip.optionvip.nome_opcao_txt
            if vp_optionvip.optionvip.tipo_opcao == u'Retorno de trafego':
                vip_map['trafficreturn'] = vp_optionvip.optionvip.id
                vip.trafficreturn = vp_optionvip.optionvip

        vip_map['host'] = vp.name
        vip_map['areanegocio'] = vp.business
        vip_map['nome_servico'] = vp.service
        vip_map['vip_ports_to_pools'] = list()

        ports = vp.viprequestport_set.all()

        # delete old ports
        pools_current = VipPortToPool.get_by_vip_id(vip.id)
        pools_ids = [pool.id for pool in pools_current]
        ports_ids = [pt.id for pt in ports]
        ids_to_del = list(set(pools_ids) - set(ports_ids))
        pools_current.filter(id__in=ids_to_del).delete()

        vip.vip_criado = vp.created
        vip.validado = True
        vip.save()

        for port in ports:
            pools = port.viprequestportpool_set.all()

            for pool in pools:
                if pool.optionvip.nome_opcao_txt in (u'default_vip'):
                    vip_port = {
                        'id': port.id,
                        'requisicao_vip': vip,
                        'server_pool': pool.server_pool,
                        'port_vip': port.port,
                        'identifier': port.identifier,
                    }
                    vip_map['vip_ports_to_pools'].append(vip_port)

                    vip_port_obj = VipPortToPool(**vip_port)
                    vip_port_obj.save()

        if int(vip_map['trafficreturn']) == 48:
            dsrl3 = VipRequestDSCP.objects.get(vip_request=vp)

            try:
                vp_dsrl3 = DsrL3_to_Vip.get_by_vip_id(vip.id)
            except:
                vp_dsrl3 = DsrL3_to_Vip()
                vp_dsrl3.requisicao_vip_id = vip.id

            vp_dsrl3.id_dsrl3 = dsrl3.dscp
            vp_dsrl3.save()
        else:
            try:
                vp_dsrl3 = DsrL3_to_Vip.get_by_vip_id(vip.id)
                vp_dsrl3.delete()
            except:
                pass

        vip.set_new_variables(vip_map)
        vip.save()

    except Exception, e:
        log.error(e)
        raise e
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:89,代码来源:syncs.py


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