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


Python Ip.get_by_octs_and_net方法代码示例

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


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

示例1: handle_post

# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import get_by_octs_and_net [as 别名]

#.........这里部分代码省略.........
                ip.oct2 = ip4[1]
                ip.oct3 = ip4[2]
                ip.oct4 = ip4[3]

                equip = Equipamento.get_by_pk(equip_id)

                listaVlansDoEquip = []

                for ipequip in equip.ipequipamento_set.all():
                    vlan = ipequip.ip.networkipv4.vlan
                    if vlan not in listaVlansDoEquip:
                        listaVlansDoEquip.append(vlan)

                for ipequip in equip.ipv6equipament_set.all():
                    vlan = ipequip.ip.networkipv6.vlan
                    if vlan not in listaVlansDoEquip:
                        listaVlansDoEquip.append(vlan)

                vlan_atual = net.vlan
                vlan_aux = None
                ambiente_aux = None

                for vlan in listaVlansDoEquip:
                    if vlan.num_vlan == vlan_atual.num_vlan:
                        if vlan.id != vlan_atual.id:

                            # Filter case 3 - Vlans with same number cannot
                            # share equipments ##

                            flag_vlan_error = False
                            # Filter testing
                            if vlan.ambiente.filter is None or vlan_atual.ambiente.filter is None:
                                flag_vlan_error = True
                            else:
                                # Test both environment's filters
                                tp_equip_list_one = list()
                                for fet in FilterEquipType.objects.filter(filter=vlan_atual.ambiente.filter.id):
                                    tp_equip_list_one.append(fet.equiptype)

                                tp_equip_list_two = list()
                                for fet in FilterEquipType.objects.filter(filter=vlan.ambiente.filter.id):
                                    tp_equip_list_two.append(fet.equiptype)

                                if equip.tipo_equipamento not in tp_equip_list_one or equip.tipo_equipamento not in tp_equip_list_two:
                                    flag_vlan_error = True

                            ## Filter case 3 - end ##

                            if flag_vlan_error:
                                ambiente_aux = vlan.ambiente
                                vlan_aux = vlan
                                nome_ambiente = "%s - %s - %s" % (
                                    vlan.ambiente.divisao_dc.nome, vlan.ambiente.ambiente_logico.nome, vlan.ambiente.grupo_l3.nome)
                                raise VlanNumberNotAvailableError(None,
                                                                  '''O ip informado não pode ser cadastrado, pois o equipamento %s, faz parte do ambiente %s (id %s), 
                                                                    que possui a Vlan de id %s, que também possui o número %s, e não é permitido que vlans que compartilhem o mesmo ambiente 
                                                                    por meio de equipamentos, possuam o mesmo número, edite o número de uma das Vlans ou adicione um filtro no ambiente para efetuar o cadastro desse IP no Equipamento Informado.
                                                                    ''' % (equip.nome, nome_ambiente, ambiente_aux.id, vlan_aux.id, vlan_atual.num_vlan))

                # Persist
                ip.save_ipv4(equip_id, user, net)

                list_ip = []
                lequips = []

                if ip.id is None:
                    ip = Ip.get_by_octs_and_net(
                        ip.oct1, ip.oct2, ip.oct3, ip.oct4, net.id)

                equips = IpEquipamento.list_by_ip(ip.id)
                ip_maps = dict()
                ip_maps['id'] = ip.id
                ip_maps['oct1'] = ip.oct1
                ip_maps['oct2'] = ip.oct2
                ip_maps['oct3'] = ip.oct3
                ip_maps['oct4'] = ip.oct4
                ip_maps['descricao'] = ip.descricao

                list_id_equip = []

                for equip in equips:
                    list_id_equip.append(equip.equipamento.id)
                    equip = Equipamento.get_by_pk(equip.equipamento.id)
                    lequips.append(model_to_dict(equip))
                ip_maps['equipamento'] = lequips
                list_ip.append(ip_maps)

                network_map = dict()
                network_map['ip'] = list_ip

                # Delete vlan's cache
                destroy_cache_function([net.vlan_id])

                # Delete equipment's cache
                destroy_cache_function(list_id_equip, True)

                return self.response(dumps_networkapi(network_map))

        except IpRangeAlreadyAssociation, e:
            return self.response_error(347)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:104,代码来源:IPv4SaveResource.py

示例2: get_dict_v4_to_use_in_configuration_deploy

# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import get_by_octs_and_net [as 别名]
def get_dict_v4_to_use_in_configuration_deploy(user, networkipv4, equipment_list):
    """Generate dictionary with vlan an IP information to be used to generate
    template dict for equipment configuration

    Args: networkipv4 NetworkIPv4 object
    equipment_list: Equipamento objects list

    Returns: 2-dimension dictionary with equipments information for template rendering
    """

    try:
        gateway_ip = Ip.get_by_octs_and_net(networkipv4.oct1, networkipv4.oct2,
                                            networkipv4.oct3, networkipv4.oct4 + 1, networkipv4)
    except IpNotFoundError:
        log.error('Equipment IPs not correctly registered. \
            Router equipments should have first IP of network allocated for them.')
        raise exceptions.IncorrectRedundantGatewayRegistryException()

    ips = IpEquipamento.objects.filter(
        ip=gateway_ip, equipamento__in=equipment_list)
    if len(ips) != len(equipment_list):
        log.error('Equipment IPs not correctly registered. \
            Router equipments should have first IP of network allocated for them.')
        raise exceptions.IncorrectRedundantGatewayRegistryException()

    dict_ips = dict()
    if networkipv4.vlan.vrf is not None and networkipv4.vlan.vrf is not '':
        dict_ips['vrf'] = networkipv4.vlan.vrf
    elif networkipv4.vlan.ambiente.vrf is not None and networkipv4.vlan.ambiente.vrf is not '':
        dict_ips['vrf'] = networkipv4.vlan.ambiente.vrf

    # DHCPRelay list
    dhcprelay_list = DHCPRelayIPv4.objects.filter(networkipv4=networkipv4)
    if len(dhcprelay_list) > 0:
        dict_ips['dhcprelay_list'] = []
        for dhcprelay in dhcprelay_list:
            ipv4 = '%s.%s.%s.%s' % (
                dhcprelay.ipv4.oct1, dhcprelay.ipv4.oct2, dhcprelay.ipv4.oct3, dhcprelay.ipv4.oct4)
            dict_ips['dhcprelay_list'].append(ipv4)

    dict_ips['gateway'] = '%d.%d.%d.%d' % (
        gateway_ip.oct1, gateway_ip.oct2, gateway_ip.oct3, gateway_ip.oct4)
    dict_ips['ip_version'] = 'IPV4'
    dict_ips['equipments'] = dict()
    dict_ips['vlan_num'] = networkipv4.vlan.num_vlan
    dict_ips['vlan_name'] = networkipv4.vlan.nome
    dict_ips['cidr_block'] = networkipv4.block
    dict_ips['mask'] = '%d.%d.%d.%d' % (
        networkipv4.mask_oct1, networkipv4.mask_oct2, networkipv4.mask_oct3, networkipv4.mask_oct4)
    dict_ips['wildmask'] = '%d.%d.%d.%d' % (
        255 - networkipv4.mask_oct1, 255 - networkipv4.mask_oct2, 255 - networkipv4.mask_oct3, 255 - networkipv4.mask_oct4)

    if _has_active_network_in_vlan(networkipv4.vlan):
        dict_ips['first_network'] = False
    else:
        dict_ips['first_network'] = True

    # Check IPs for routers when there are multiple gateways
    if len(equipment_list) > 1:
        dict_ips['gateway_redundancy'] = True
        equip_number = 0
        for equipment in equipment_list:
            ip_equip = IpEquipamento.objects.filter(equipamento=equipment, ip__networkipv4=networkipv4).exclude(ip=gateway_ip)\
                .select_related('ip')
            if ip_equip == []:
                log.error('Error: Equipment IPs not correctly registered. \
                    In case of multiple gateways, they should have an IP other than the gateway registered.')
                raise exceptions.IncorrectNetworkRouterRegistryException()
            ip = ip_equip[0].ip
            dict_ips[equipment] = dict()
            dict_ips[equipment]['ip'] = '%s.%s.%s.%s' % (
                ip.oct1, ip.oct2, ip.oct3, ip.oct4)
            dict_ips[equipment]['prio'] = 100 + equip_number
            equip_number += 1
    else:
        dict_ips['gateway_redundancy'] = False
        dict_ips[equipment_list[0]] = dict()
        dict_ips[equipment_list[0]]['ip'] = dict_ips['gateway']
        dict_ips[equipment_list[0]]['prio'] = 100

    return dict_ips
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:83,代码来源:v1.py

示例3: get_dict_v4_to_use_in_configuration_deploy

# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import get_by_octs_and_net [as 别名]
def get_dict_v4_to_use_in_configuration_deploy(user, networkipv4, equipment_list):
	'''Generate dictionary with vlan an IP information to be used to generate
	template dict for equipment configuration

	Args: networkipv4 NetworkIPv4 object
	equipment_list: Equipamento objects list

	Returns: 2-dimension dictionary with equipments information for template rendering
	'''

	try:
		gateway_ip = Ip.get_by_octs_and_net(networkipv4.oct1, networkipv4.oct2,
			networkipv4.oct3, networkipv4.oct4+1, networkipv4)
	except IpNotFoundError:
		log.error("Equipment IPs not correctly registered. \
			Router equipments should have first IP of network allocated for them.")
		raise exceptions.IncorrectRedundantGatewayRegistryException()

	ips = IpEquipamento.objects.filter(ip=gateway_ip, equipamento__in=equipment_list)
	if len(ips) != len(equipment_list):
		log.error("Equipment IPs not correctly registered. \
			Router equipments should have first IP of network allocated for them.")
		raise exceptions.IncorrectRedundantGatewayRegistryException()

	dict_ips = dict()
	if networkipv4.vlan.vrf is not None and networkipv4.vlan.vrf is not '':
		dict_ips["vrf"] = networkipv4.vlan.vrf
	elif networkipv4.vlan.ambiente.vrf is not None and networkipv4.vlan.ambiente.vrf is not '':
		dict_ips["vrf"] = networkipv4.vlan.ambiente.vrf

	dict_ips["gateway"] = "%d.%d.%d.%d" % (gateway_ip.oct1, gateway_ip.oct2, gateway_ip.oct3, gateway_ip.oct4) 
	dict_ips["ip_version"] = "IPV4"
	dict_ips["equipments"] = dict()
	dict_ips["vlan_num"] = networkipv4.vlan.num_vlan
	dict_ips["vlan_name"] = networkipv4.vlan.nome
	dict_ips["cidr_block"] = networkipv4.block
	dict_ips["mask"] = "%d.%d.%d.%d" % (networkipv4.mask_oct1, networkipv4.mask_oct2, networkipv4.mask_oct3, networkipv4.mask_oct4)
	dict_ips["wildmask"] = "%d.%d.%d.%d" % (255-networkipv4.mask_oct1, 255-networkipv4.mask_oct2, 255-networkipv4.mask_oct3, 255-networkipv4.mask_oct4)

	if _has_active_network_in_vlan(networkipv4.vlan):
		dict_ips["first_network"] = False
	else:
		dict_ips["first_network"] = True

	#Check IPs for routers when there are multiple gateways
	if len(equipment_list) > 1:
		dict_ips["gateway_redundancy"] = True
		equip_number = 0
		for equipment in equipment_list:
			ip_equip = IpEquipamento.objects.filter(equipamento=equipment, ip__networkipv4=networkipv4).exclude(ip=gateway_ip)\
                .select_related('ip')
			if ip_equip == []:
				log.error("Error: Equipment IPs not correctly registered. \
					In case of multiple gateways, they should have an IP other than the gateway registered.")
				raise exceptions.IncorrectNetworkRouterRegistryException
			ip = ip_equip[0].ip
			dict_ips[equipment] = dict()
			dict_ips[equipment]["ip"] = "%s.%s.%s.%s" % (ip.oct1, ip.oct2, ip.oct3, ip.oct4)
			dict_ips[equipment]["prio"] = 100+equip_number
			equip_number += 1
	else:
		dict_ips["gateway_redundancy"] = False
		dict_ips[equipment_list[0]] = dict()
		dict_ips[equipment_list[0]]["ip"] = dict_ips["gateway"]
		dict_ips[equipment_list[0]]["prio"] = 100

	return dict_ips
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:69,代码来源:facade.py


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