How to use the autonetkit.ank.copy_attr_from 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 sk2 / autonetkit / autonetkit / test_ank.py View on Github external
# Can specify a default value if unset
        nodes = ["r1", "r2", "r3"]
        r1 = g_in.node('r1')
        r2 = g_in.node('r2')
        r3 = g_in.node('r3')
        r4 = g_in.node('r4')
        r5 = g_in.node('r5')
        ank_utils.set_node_default(g_in, nodes, role="core")
        ank_utils.copy_attr_from(g_in, g_phy, "role", default="edge")
        result = [(n, n.get("role")) for n in g_phy]
        expected_result = [(r4, 'edge'), (r5, 'edge'), (r1, 'core'),
                           (r2, 'core'), (r3, 'core')]

        self.assertListEqual(expected_result, result)
        # Can specify the remote attribute to set
        ank_utils.copy_attr_from(g_in, g_phy, "role",
                                "device_role", default="edge")
        result = [(n, n.get('device_role')) for n in g_phy]
        expected_result = [(n, n.get('role') if n.get('role') else 'edge')
                           for n in g_in]
        self.assertListEqual(expected_result, result)
        # Can specify the type to cast to
        g_in.update(memory = "32")
        ank_utils.copy_attr_from(g_in, g_phy, "memory", type=int)
        result = [n.get("memory") for n in g_phy]
        expected_result = [32, 32, 32, 32, 32]
        self.assertEqual(expected_result, result)
github datacenter / ignite-DEPRECATED / ank / autonetkit / autonetkit / build_network.py View on Github external
g_in.data.enable_routing = True  # default if not set

    g_phy.add_nodes_from(g_in, retain=['label', 'update', 'device_type', 'devsubtype',
                                       'asn', 'specified_int_names', 'x', 'y',
                                       'device_subtype', 'platform', 'host', 'syntax',
                                       'profile', 'syslog'])

    if g_in.data.Creator == "Topology Zoo Toolset":
        ank_utils.copy_attr_from(g_in, g_phy, "Network")

    ank_utils.set_node_default(g_phy, Network=None)
    g_phy.add_edges_from(g_in.edges(type="physical"))
    # TODO: make this automatic if adding to the physical graph?

    ank_utils.set_node_default(g_phy, use_ipv4=False, use_ipv6=False)
    ank_utils.copy_attr_from(g_in, g_phy, "custom_config_global",
                             dst_attr="custom_config")

    for node in g_phy:
        if node['input'].custom_config_loopback_zero:
            lo_zero_config = node['input'].custom_config_loopback_zero
            node.loopback_zero.custom_config = lo_zero_config
        custom_config_phy_ints = node['input'].custom_config_phy_ints
        for interface in node:
            if custom_config_phy_ints:
                interface.custom_config = custom_config_phy_ints
            specified_id = interface['input'].get("specified_id")
            if specified_id:
                interface.specified_id = specified_id  # map across

    #TODO: tidy this code up
    for node in g_phy:
github datacenter / ignite-DEPRECATED / autonetkit / design / ip_addressing / ipv4.py View on Github external
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""

    import autonetkit.plugins.ipv4 as ipv4
    import netaddr
    g_ipv4 = anm.add_overlay('ipv4')
    g_ip = anm['ip']
    g_in = anm['input']
    # retain if collision domain or not
    g_ipv4.add_nodes_from(g_ip, retain=['label', 'allocate',
                                        'broadcast_domain'])
    ank_utils.copy_attr_from(g_in, g_ipv4, 'name')
    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)

    ank_utils.copy_attr_from(
        g_ip, g_ipv4, 'asn', nbunch=g_ipv4.nodes('broadcast_domain'))
    # work around until fall-through implemented
    vswitches = [n for n in g_ip.nodes()
                 if n['layer2'].device_type == "switch"
                 and n['layer2'].device_subtype == "virtual"]
    ank_utils.copy_attr_from(g_ip, g_ipv4, 'asn', nbunch=vswitches)
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in

    (infra_block, loopback_block, vrf_loopback_block) = \
        extract_ipv4_blocks(anm)
github sk2 / autonetkit / autonetkit / design / ip_addressing / ipv4.py View on Github external
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""

    import autonetkit.plugins.ipv4 as ipv4
    import netaddr
    g_ipv4 = anm.add_overlay('ipv4')
    g_ip = anm['ip']
    g_in = anm['input']
    # retain if collision domain or not
    g_ipv4.add_nodes_from(g_ip, retain=['label', 'allocate',
                                        'broadcast_domain'])

    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)

    ank_utils.copy_attr_from(
        g_ip, g_ipv4, 'asn', nbunch=g_ipv4.nodes('broadcast_domain'))
    # work around until fall-through implemented
    vswitches = [n for n in g_ip.nodes()
                 if n['layer2'].device_type == "switch"
                 and n['layer2'].device_subtype == "virtual"]
    ank_utils.copy_attr_from(g_ip, g_ipv4, 'asn', nbunch=vswitches)
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in

    (infra_block, loopback_block, vrf_loopback_block) = \
        extract_ipv4_blocks(anm)

# TODO: don't present if using manual allocation
    if any(i for n in g_ip.nodes() for i in
           n.loopback_interfaces() if not i.is_loopback_zero):
github sk2 / autonetkit / autonetkit / design / igp.py View on Github external
g_isis = anm.add_overlay("isis")

    if not anm['phy'].data.enable_routing:
        g_isis.log.info("Routing disabled, not configuring ISIS")
        return

    if not any(n.igp == "isis" for n in g_phy):
        g_isis.log.debug("No ISIS nodes")
        return

    isis_nodes = [n for n in g_l3 if n['phy'].igp == "isis"]
    g_isis.add_nodes_from(isis_nodes)
    g_isis.add_edges_from(g_l3.edges(), warn=False)
    ank_utils.copy_int_attr_from(g_l3, g_isis, "multipoint")

    ank_utils.copy_attr_from(
        g_in, g_isis, "custom_config_isis", dst_attr="custom_config")

    g_isis.remove_edges_from(
        [link for link in g_isis.edges() if link.src.asn != link.dst.asn])

    build_network_entity_title(anm)

    for node in g_isis.routers():
        node.process_id = node.asn

    for link in g_isis.edges():
        link.metric = 1  # default

    for edge in g_isis.edges():
        for interface in edge.interfaces():
            interface.metric = edge.metric
github datacenter / ignite-DEPRECATED / autonetkit / build_network.py View on Github external
if address_family == "None":
        log.info("IP addressing disabled, not allocating IPv6")
        anm.add_overlay("ipv6")  # create empty so rest of code follows
        g_phy.update(g_phy, use_ipv6=False)
    elif address_family in ("v6", "dual_stack"):
        build_ipv6(anm)
        g_phy.update(g_phy, use_ipv6=True)
    else:
        anm.add_overlay("ipv6")  # placeholder for compiler logic
    assign_loopback_ip_pool(anm)
    #default_igp = g_in.data.igp or "ospf"
    default_igp = g_in.data.igp
    ank_utils.set_node_default(g_in, igp=default_igp)
    ank_utils.copy_attr_from(g_in, g_phy, "igp")

    ank_utils.copy_attr_from(g_in, g_phy, "include_csr")

    try:
        from autonetkit_cisco import build_network as cisco_build_network
    except ImportError, error:
        log.debug("Unable to load autonetkit_cisco %s" % error)
    else:
        cisco_build_network.pre_design(anm)

    # log.info("Building IGP")
    from autonetkit.design.igp import build_igp
    build_igp(anm)

    # log.info("Building BGP")
    from autonetkit.design.bgp import build_bgp
    build_bgp(anm)
    # autonetkit.update_vis(anm)
github sk2 / autonetkit / autonetkit / design / bgp.py View on Github external
def build_ibgp(anm):
    g_in = anm['input']
    g_bgp = anm['bgp']

    # TODO: build direct to ibgp graph - can construct combined bgp for vis
    #TODO: normalise input property

    ank_utils.copy_attr_from(g_in, g_bgp, "ibgp_role")
    ank_utils.copy_attr_from(
        g_in, g_bgp, "ibgp_l2_cluster", "hrr_cluster", default=None)
    ank_utils.copy_attr_from(
        g_in, g_bgp, "ibgp_l3_cluster", "rr_cluster", default=None)

    # TODO: add more detailed logging

    for n in g_bgp:
        # Tag with label to make logic clearer
        if n.ibgp_role is None:
            n.ibgp_role = "Peer"

            # TODO: if top-level, then don't mark as RRC

    ibgp_nodes = [n for n in g_bgp if not n.ibgp_role is "Disabled"]

    # Notify user of non-ibgp nodes
github datacenter / ignite-DEPRECATED / autonetkit / design / ip_addressing / ipv4.py View on Github external
g_ipv4 = anm.add_overlay('ipv4')
    g_ip = anm['ip']
    g_in = anm['input']
    # retain if collision domain or not
    g_ipv4.add_nodes_from(g_ip, retain=['label', 'allocate',
                                        'broadcast_domain'])
    ank_utils.copy_attr_from(g_in, g_ipv4, 'name')
    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)

    ank_utils.copy_attr_from(
        g_ip, g_ipv4, 'asn', nbunch=g_ipv4.nodes('broadcast_domain'))
    # work around until fall-through implemented
    vswitches = [n for n in g_ip.nodes()
                 if n['layer2'].device_type == "switch"
                 and n['layer2'].device_subtype == "virtual"]
    ank_utils.copy_attr_from(g_ip, g_ipv4, 'asn', nbunch=vswitches)
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in

    (infra_block, loopback_block, vrf_loopback_block) = \
        extract_ipv4_blocks(anm)

# TODO: don't present if using manual allocation
    if any(i for n in g_ip.nodes() for i in
           n.loopback_interfaces() if not i.is_loopback_zero):
        block_message = "IPv4 Secondary Loopbacks: %s" % vrf_loopback_block
        log.info(block_message)

    # See if IP addresses specified on each interface

    # do we need this still? in ANM? - differnt because input graph.... but
github sk2 / autonetkit / autonetkit / design / ip_addressing / ipv4.py View on Github external
g_ipv4 = anm.add_overlay('ipv4')
    g_ip = anm['ip']
    g_in = anm['input']
    # retain if collision domain or not
    g_ipv4.add_nodes_from(g_ip, retain=['label', 'allocate',
                                        'broadcast_domain'])

    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)

    ank_utils.copy_attr_from(
        g_ip, g_ipv4, 'asn', nbunch=g_ipv4.nodes('broadcast_domain'))
    # work around until fall-through implemented
    vswitches = [n for n in g_ip.nodes()
                 if n['layer2'].device_type == "switch"
                 and n['layer2'].device_subtype == "virtual"]
    ank_utils.copy_attr_from(g_ip, g_ipv4, 'asn', nbunch=vswitches)
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in

    (infra_block, loopback_block, vrf_loopback_block) = \
        extract_ipv4_blocks(anm)

# TODO: don't present if using manual allocation
    if any(i for n in g_ip.nodes() for i in
           n.loopback_interfaces() if not i.is_loopback_zero):
        block_message = "IPv4 Secondary Loopbacks: %s" % vrf_loopback_block
        log.info(block_message)

    # See if IP addresses specified on each interface

    # do we need this still? in ANM? - differnt because input graph.... but
github sk2 / autonetkit / autonetkit / build_network.py View on Github external
g_phy.update(g_phy, use_ipv4=False)

        # TODO: Create collision domain overlay for ip addressing - l2 overlay?
        if address_family == "None":
            log.info("IP addressing disabled, not allocating IPv6")
            anm.add_overlay("ipv6")  # create empty so rest of code follows
            g_phy.update(g_phy, use_ipv6=False)
        elif address_family in ("v6", "dual_stack"):
            build_ipv6(anm)
            g_phy.update(g_phy, use_ipv6=True)
        else:
            anm.add_overlay("ipv6")  # placeholder for compiler logic

        default_igp = g_in.data.igp or "ospf"
        ank_utils.set_node_default(g_in, igp=default_igp)
        ank_utils.copy_attr_from(g_in, g_phy, "igp")

        ank_utils.copy_attr_from(g_in, g_phy, "include_csr")

        # log.info("Building IGP")
        from autonetkit.design.igp import build_igp
        build_igp(anm)

        # log.info("Building BGP")
        from autonetkit.design.bgp import build_bgp
        build_bgp(anm)
        # autonetkit.update_vis(anm)

        from autonetkit.design.mpls import mpls_te, mpls_oam
        mpls_te(anm)
        mpls_oam(anm)