How to use the autonetkit.ank.sn_preflen_to_network function in autonetkit

To help you get started, we’ve selected a few autonetkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datacenter / ignite-DEPRECATED / autonetkit / design / ip_addressing / ipv4.py View on Github external
def extract_ipv4_blocks(anm):

    # TODO: set all these blocks globally in config file, rather than repeated
    # in load, build_network, compile, etc

    from netaddr import IPNetwork
    g_in = anm['input']
    ipv4_defaults = SETTINGS["IP Addressing"]["v4"]

    # TODO: wrap these in a common function

    try:
        infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        infra_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["infra_subnet"], ipv4_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv4 infra_subnet %s' % infra_block)
        else:
            log.warning('Unable to obtain IPv4 infra_subnet from input graph: %s, using default %s' % (
                e, infra_block))

    try:
        loopback_subnet = g_in.data.ipv4_loopback_subnet
        loopback_prefix = g_in.data.ipv4_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        loopback_block = IPNetwork(
github datacenter / ignite-DEPRECATED / autonetkit / design / ip_addressing / ipv4.py View on Github external
infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        infra_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["infra_subnet"], ipv4_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv4 infra_subnet %s' % infra_block)
        else:
            log.warning('Unable to obtain IPv4 infra_subnet from input graph: %s, using default %s' % (
                e, infra_block))

    try:
        loopback_subnet = g_in.data.ipv4_loopback_subnet
        loopback_prefix = g_in.data.ipv4_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        loopback_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["loopback_subnet"], ipv4_defaults["loopback_prefix"]))
        if loopback_subnet is None or loopback_prefix is None:
            log.debug('Using default IPv4 loopback_subnet %s' % loopback_block)
        else:
            log.warning('Unable to obtain IPv4 loopback_subnet from input graph: %s, using default %s' % (
                e, loopback_block))

    try:
        vrf_loopback_subnet = g_in.data.ipv4_vrf_loopback_subnet
        vrf_loopback_prefix = g_in.data.ipv4_vrf_loopback_prefix
        vrf_loopback_block = sn_preflen_to_network(vrf_loopback_subnet,
                                                   vrf_loopback_prefix)
    except Exception, e:
github datacenter / ignite-DEPRECATED / ank / autonetkit / autonetkit / compilers / device / cisco.py View on Github external
ipv4_loopback_zero = phy_loopback_zero['ipv4']
            ipv4_address = ipv4_loopback_zero.ip_address
            node.loopback_zero.use_ipv4 = True
            node.loopback_zero.ipv4_address = ipv4_address
            node.loopback_zero.ipv4_subnet = ipv4_loopback_subnet
            node.loopback_zero.ipv4_cidr = \
                sn_preflen_to_network(ipv4_address,
                                      ipv4_loopback_subnet.prefixlen)

        if node.ip.use_ipv6:
            # TODO: clean this up so can set on router_base: call cidr not
            # address and update templates
            node.loopback_zero.use_ipv6 = True
            ipv6_loopback_zero = phy_loopback_zero['ipv6']
            node.loopback_zero.ipv6_address = \
                sn_preflen_to_network(ipv6_loopback_zero.ip_address,
                                      128)

        super(IosBaseCompiler, self).interfaces(node)

        for interface in node.physical_interfaces():
            interface.use_cdp = node.use_cdp  # use node value

        for interface in node.interfaces:
            interface.sub_ints = []  # temporary until full subinterfaces
github sk2 / autonetkit / autonetkit / design / ip_addressing / ipv6.py View on Github external
infra_prefix = g_in.data.ipv6_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, error:
        infra_block = IPNetwork(
            '%s/%s' % (ipv6_defaults["infra_subnet"],
                       ipv6_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv6 infra_subnet %s', infra_block)
        else:
            log.warning('Unable to obtain IPv6 infra_subnet from input graph: %s, using default %s' % (
                error, infra_block))

    try:
        loopback_subnet = g_in.data.ipv6_loopback_subnet
        loopback_prefix = g_in.data.ipv6_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, error:
        loopback_block = IPNetwork(
            '%s/%s' % (ipv6_defaults["loopback_subnet"],
                       ipv6_defaults["loopback_prefix"]))
        if loopback_subnet is None or loopback_prefix is None:
            log.debug('Using default IPv6 loopback_subnet %s',
                      loopback_block)
        else:
            log.warning('Unable to obtain IPv6 loopback_subnet from" input graph: %s, using default %s' % (
                error, loopback_block))

    try:
        vrf_loopback_subnet = g_in.data.ipv6_vrf_loopback_subnet
        vrf_loopback_prefix = g_in.data.ipv6_vrf_loopback_prefix
        vrf_loopback_block = sn_preflen_to_network(vrf_loopback_subnet,
github sk2 / autonetkit / autonetkit / design / ip_addressing / ipv6.py View on Github external
interface.ip_address = ip_address
            interface.prefixlen = prefixlen
            cidr_string = '%s/%s' % (ip_address, prefixlen)
            interface.subnet = netaddr.IPNetwork(cidr_string)

    broadcast_domains = [d for d in g_ipv6 if d.broadcast_domain]

    # TODO: allow this to work with specified ip_address/subnet as well as
    # ip_address/prefixlen

    global_infra_block = None
    try:
        # Note this is only pickling up if explictly set in g_in
        infra_subnet = g_in.data.ipv6_infra_subnet
        infra_prefix = g_in.data.ipv6_infra_prefix
        global_infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        log.info("Unable to parse specified ipv4 infra subnets %s/%s")

    from netaddr import IPNetwork
    mismatched_interfaces = []

    for coll_dom in broadcast_domains:
        connected_interfaces = [edge.dst_int for edge in
                                coll_dom.edges()]
        cd_subnets = [IPNetwork('%s/%s' % (i.subnet.network,
                                           i.prefixlen)) for i in connected_interfaces]

        if global_infra_block is not None:
            mismatched_interfaces += [i for i in connected_interfaces
            if i.ip_address not in global_infra_block]
github sk2 / autonetkit / autonetkit / design / ip_addressing / ipv4.py View on Github external
def extract_ipv4_blocks(anm):

    # TODO: set all these blocks globally in config file, rather than repeated
    # in load, build_network, compile, etc

    from netaddr import IPNetwork
    g_in = anm['input']
    ipv4_defaults = SETTINGS["IP Addressing"]["v4"]

    # TODO: wrap these in a common function

    try:
        infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        infra_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["infra_subnet"], ipv4_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv4 infra_subnet %s' % infra_block)
        else:
            log.warning('Unable to obtain IPv4 infra_subnet from input graph: %s, using default %s' % (
                e, infra_block))

    try:
        loopback_subnet = g_in.data.ipv4_loopback_subnet
        loopback_prefix = g_in.data.ipv4_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        loopback_block = IPNetwork(
github sk2 / autonetkit / autonetkit / design / ip_addressing / ipv4.py View on Github external
loopback_prefix = g_in.data.ipv4_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        loopback_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["loopback_subnet"], ipv4_defaults["loopback_prefix"]))
        if loopback_subnet is None or loopback_prefix is None:
            log.debug('Using default IPv4 loopback_subnet %s' % loopback_block)
        else:
            log.warning('Unable to obtain IPv4 loopback_subnet from input graph: %s, using default %s' % (
                e, loopback_block))

    try:
        vrf_loopback_subnet = g_in.data.ipv4_vrf_loopback_subnet
        vrf_loopback_prefix = g_in.data.ipv4_vrf_loopback_prefix
        vrf_loopback_block = sn_preflen_to_network(vrf_loopback_subnet,
                                                   vrf_loopback_prefix)
    except Exception, e:
        vrf_loopback_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["vrf_loopback_subnet"], ipv4_defaults["vrf_loopback_prefix"]))
        if vrf_loopback_subnet is None or vrf_loopback_prefix is None:
            log.debug('Using default IPv4 vrf_loopback_subnet %s' %
                      vrf_loopback_block)
        else:
            log.warning('Unable to obtain IPv4 vrf_loopback_subnet from input graph: %s, using default %s' % (
                e, vrf_loopback_block))

    return (infra_block, loopback_block, vrf_loopback_block)
github sk2 / autonetkit / autonetkit / design / ip_addressing / ipv4.py View on Github external
infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        infra_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["infra_subnet"], ipv4_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv4 infra_subnet %s' % infra_block)
        else:
            log.warning('Unable to obtain IPv4 infra_subnet from input graph: %s, using default %s' % (
                e, infra_block))

    try:
        loopback_subnet = g_in.data.ipv4_loopback_subnet
        loopback_prefix = g_in.data.ipv4_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        loopback_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["loopback_subnet"], ipv4_defaults["loopback_prefix"]))
        if loopback_subnet is None or loopback_prefix is None:
            log.debug('Using default IPv4 loopback_subnet %s' % loopback_block)
        else:
            log.warning('Unable to obtain IPv4 loopback_subnet from input graph: %s, using default %s' % (
                e, loopback_block))

    try:
        vrf_loopback_subnet = g_in.data.ipv4_vrf_loopback_subnet
        vrf_loopback_prefix = g_in.data.ipv4_vrf_loopback_prefix
        vrf_loopback_block = sn_preflen_to_network(vrf_loopback_subnet,
                                                   vrf_loopback_prefix)
    except Exception, e:
github sk2 / autonetkit / autonetkit / compilers / device / cisco.py View on Github external
ipv4_loopback_zero = phy_loopback_zero['ipv4']
            ipv4_address = ipv4_loopback_zero.ip_address
            node.loopback_zero.use_ipv4 = True
            node.loopback_zero.ipv4_address = ipv4_address
            node.loopback_zero.ipv4_subnet = ipv4_loopback_subnet
            node.loopback_zero.ipv4_cidr = \
                sn_preflen_to_network(ipv4_address,
                                      ipv4_loopback_subnet.prefixlen)

        if node.ip.use_ipv6:
            # TODO: clean this up so can set on router_base: call cidr not
            # address and update templates
            node.loopback_zero.use_ipv6 = True
            ipv6_loopback_zero = phy_loopback_zero['ipv6']
            node.loopback_zero.ipv6_address = \
                sn_preflen_to_network(ipv6_loopback_zero.ip_address,
                                      128)

        super(IosBaseCompiler, self).interfaces(node)

        for interface in node.physical_interfaces():
            interface.use_cdp = node.use_cdp  # use node value

        for interface in node.interfaces:
            interface.sub_ints = []  # temporary until full subinterfaces

        for interface in node.physical_interfaces():
            g_ext_conn = self.anm['ext_conn']
            if node not in g_ext_conn:
                continue

            node_ext_conn = g_ext_conn.node(node)
github sk2 / autonetkit / autonetkit / design / ip_addressing / ipv6.py View on Github external
def extract_ipv6_blocks(anm):

    # TODO: set all these blocks globally in config file, rather than repeated
    # in load, build_network, compile, etc

    from autonetkit.ank import sn_preflen_to_network
    from netaddr import IPNetwork
    g_in = anm['input']

    ipv6_defaults = SETTINGS["IP Addressing"]["v6"]

    try:
        infra_subnet = g_in.data.ipv6_infra_subnet
        infra_prefix = g_in.data.ipv6_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, error:
        infra_block = IPNetwork(
            '%s/%s' % (ipv6_defaults["infra_subnet"],
                       ipv6_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv6 infra_subnet %s', infra_block)
        else:
            log.warning('Unable to obtain IPv6 infra_subnet from input graph: %s, using default %s' % (
                error, infra_block))

    try:
        loopback_subnet = g_in.data.ipv6_loopback_subnet
        loopback_prefix = g_in.data.ipv6_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, error: