Exemplo n.º 1
0
def create_nidb(anm):
    #TODO: refactor this now with the layer2/layer2_bc graphs - what does NIDB need?
    # probably just layer2, and then allow compiled to access layer2_bc if need (eg netkit?)
    nidb = DeviceModel()
    g_phy = anm['phy']
    g_ip = anm['ip']
    g_layer2_bc = anm['layer2_bc']
    g_graphics = anm['graphics']
    nidb.add_nodes_from(
        g_phy, retain=['label', 'host', 'platform', 'Network', 'update', 'asn'])

    cd_nodes = [n for n in g_ip.nodes(
        "broadcast_domain") if not n.is_switch()]  # Only add created cds - otherwise overwrite host of switched
    nidb.add_nodes_from(
        cd_nodes, retain=['label', 'host'], broadcast_domain=True)

    for node in nidb.nodes("broadcast_domain"):
        ipv4_node = anm['ipv4'].node(node)
        if ipv4_node:
            node.ipv4_subnet = ipv4_node.subnet
            #TODO: copy across IPv6 seperately
            node.ipv6_subnet = ipv4_node['ipv6'].subnet

# add edges to switches
    edges_to_add = [edge for edge in g_phy.edges()
                    if edge.src.is_switch() or edge.dst.is_switch()]
    # cd edges from split
    edges_to_add += [edge for edge in g_layer2_bc.edges()]
    nidb.add_edges_from(edges_to_add)

    nidb.copy_graphics(g_graphics)

    return nidb
Exemplo n.º 2
0
def create_nidb(anm):

    # todo: refactor this now with the layer2/layer2_bc graphs - what does nidb need?
    # probably just layer2, and then allow compiled to access layer2_bc if need (eg netkit?)

    nidb = DeviceModel()
    g_phy = anm['phy']
    g_graphics = anm['graphics']
    nidb.add_nodes_from(g_phy, retain=[
        'label',
        'host',
        'platform',
        'Network',
        'update',
        'asn',
        ])

    # cd_nodes = [n for n in g_ip.nodes("broadcast_domain") if not n.is_switch()]  # Only add created cds - otherwise overwrite host of switched
    # also copy virtual switches
    # TODO: refactor this
    # nidb.add_nodes_from(cd_nodes, retain=['label', 'host'], broadcast_domain=True)

    nidb.add_edges_from(g_phy.edges())

    nidb.copy_graphics(g_graphics)

    return nidb
Exemplo n.º 3
0
def create_nidb(anm):

    # todo: refactor this now with the layer2/layer2_bc graphs - what does nidb need?
    # probably just layer2, and then allow compiled to access layer2_bc if
    # need (eg netkit?)

    nidb = DeviceModel(anm)

    return nidb
Exemplo n.º 4
0
            #start = time.clock()
            autonetkit.render.render(nidb)
            #print time.clock() - start
            #import autonetkit.render2
            #start = time.clock()
            #autonetkit.render2.render(nidb)
            #print time.clock() - start

    if not (build or compile):

        # Load from last run

        import autonetkit.anm
        anm = autonetkit.anm.NetworkModel()
        anm.restore_latest()
        nidb = DeviceModel()
        nidb.restore_latest()
        #autonetkit.update_vis(anm, nidb)

    if diff:
        import autonetkit.diff
        nidb_diff = autonetkit.diff.nidb_diff()
        import json
        data = json.dumps(nidb_diff, cls=ank_json.AnkEncoder, indent=4)
        log.info('Wrote diff to diff.json')

        # TODO: make file specified in config

        with open('diff.json', 'w') as fh:
            fh.write(data)
Exemplo n.º 5
0
            #start = time.clock()
            autonetkit.render.render(nidb)
            # print time.clock() - start
            #import autonetkit.render2
            #start = time.clock()
            # autonetkit.render2.render(nidb)
            # print time.clock() - start

    if not (build or compile):

        # Load from last run

        import autonetkit.anm
        anm = autonetkit.anm.NetworkModel()
        anm.restore_latest()
        nidb = DeviceModel()
        nidb.restore_latest()
        #autonetkit.update_vis(anm, nidb)

    if diff:
        import autonetkit.diff
        nidb_diff = autonetkit.diff.nidb_diff()
        import json
        data = json.dumps(nidb_diff, cls=ank_json.AnkEncoder, indent=4)
        # log.info('Wrote diff to diff.json')

        # TODO: make file specified in config

        with open('diff.json', 'w') as fh:
            fh.write(data)
Exemplo n.º 6
0
def create_nidb(anm):
    #TODO: refactor this now with the layer2/layer2_bc graphs - what does NIDB need?
    # probably just layer2, and then allow compiled to access layer2_bc if need (eg netkit?)
    nidb = DeviceModel()
    g_phy = anm['phy']
    g_ip = anm['ip']
    g_layer2_bc = anm['layer2_bc']
    g_graphics = anm['graphics']
    nidb.add_nodes_from(
        g_phy,
        retain=['label', 'host', 'platform', 'Network', 'update', 'asn'])

    cd_nodes = [
        n for n in g_ip.nodes("broadcast_domain") if not n.is_switch()
    ]  # Only add created cds - otherwise overwrite host of switched
    nidb.add_nodes_from(cd_nodes,
                        retain=['label', 'host'],
                        broadcast_domain=True)

    for node in nidb.nodes("broadcast_domain"):
        ipv4_node = anm['ipv4'].node(node)
        if ipv4_node:
            node.ipv4_subnet = ipv4_node.subnet
            #TODO: copy across IPv6 seperately
            node.ipv6_subnet = ipv4_node['ipv6'].subnet


# add edges to switches
    edges_to_add = [
        edge for edge in g_phy.edges()
        if edge.src.is_switch() or edge.dst.is_switch()
    ]
    # cd edges from split
    edges_to_add += [edge for edge in g_layer2_bc.edges()]
    nidb.add_edges_from(edges_to_add)

    nidb.copy_graphics(g_graphics)

    return nidb