Esempio n. 1
0
def subtract_network(
        container_network: ipaddress.IPv4Network,
        contained_network: ipaddress.IPv4Network
) -> List[ipaddress.IPv4Network]:
    if contained_network.subnet_of(container_network):
        return list(container_network.address_exclude(contained_network))

    return []
    def large_absorb_small(
            aggregated_supernet: Tuple[List[IPv4Network], IPv4Network],
            net: IPv4Network) -> Tuple[List[IPv4Network], IPv4Network]:
        aggregated, supernet = aggregated_supernet

        if not net.subnet_of(supernet):  # type: ignore
            aggregated.append(net)
            supernet = net

        return aggregated, supernet
Esempio n. 3
0
def remove_subnet(subnets: List[IPv4Network],
                  exclude: IPv4Network) -> List[IPv4Network]:
    result = []
    # Find which subnet the exclusion is part of
    for sub in subnets:
        # If found, exclude & add the result
        if exclude.subnet_of(sub):
            result.extend(list(sub.address_exclude(exclude)))
        else:
            # Other subnets can be added directly
            result.append(sub)

    # Collapse in case of overlaps
    new_result = list(collapse_addresses(result))
    new_result.sort()
    return new_result