예제 #1
0
def manage_network(input_graph_string, timestamp, build_options, reload_build=False, grid = None):
    """Build, compile, render network as appropriate"""
    # import build_network_simple as build_network
    import autonetkit.build_network as build_network
    if reload_build:
# remap?
        build_network = reload(build_network)

    if build_options['build']:
        if input_graph_string:
            graph = build_network.load(input_graph_string)
        elif grid:
            graph = build_network.grid_2d(grid)

        anm = build_network.build(graph)
        if not build_options['compile']:
            update_http(anm)

        if build_options['validate']:
            import autonetkit.ank_validate
            autonetkit.ank_validate.validate(anm)

    if build_options['compile']:
        if build_options['archive']:
            anm.save()
        nidb = compile_network(anm)

        update_http(anm, nidb)
        log.debug("Sent ANM to web server")
        if build_options['archive']:
            nidb.save()
        # render.remove_dirs(["rendered"])
        if build_options['render']:
            render.render(nidb)

    if not(build_options['build'] or build_options['compile']):
        # Load from last run
        import autonetkit.anm
        anm = autonetkit.anm.AbstractNetworkModel()
        anm.restore_latest()
        nidb = NIDB()
        nidb.restore_latest()
        update_http(anm, nidb)

    if build_options['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")
        with open("diff.json", "w") as fh:  # TODO: make file specified in config
            fh.write(data)

    if build_options['deploy']:
        deploy_network(anm, nidb, input_graph_string)

    if build_options['measure']:
        measure_network(anm, nidb)

    log.info("Finished")
예제 #2
0
def create_nidb(anm):
    nidb = NIDB()
    g_phy = anm['phy']
    g_ip = anm['ip']
    g_graphics = anm['graphics']
# TODO: build this on a platform by platform basis
    nidb.add_nodes_from(
        g_phy, retain=['label', 'host', 'platform', 'Network', 'update'])

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

    #TODO: write a helper functions to do this
    for node in nidb.nodes("collision_domain"):
        ipv4_node = anm['ipv4'].node(node)
        node.ipv4_subnet = ipv4_node.subnet
        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]
    edges_to_add += [edge for edge in g_ip.edges() if edge.split] # cd edges from split
    nidb.add_edges_from(edges_to_add, retain='edge_id')

# TODO: boundaries is still a work in progress...
    nidb.copy_graphics(g_graphics)

    return nidb
예제 #3
0
def create_nidb(anm):
    nidb = NIDB()
    g_phy = anm['phy']
    g_ip = anm['ip']
    g_graphics = anm['graphics']
    nidb.add_nodes_from(
        g_phy, retain=['label', 'host', 'platform', 'Network', 'update'])

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

    for node in nidb.nodes("collision_domain"):
        ipv4_node = anm['ipv4'].node(node)
        if ipv4_node:
            node.ipv4_subnet = ipv4_node.subnet
            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]
    edges_to_add += [edge for edge in g_ip.edges() if edge.split] # cd edges from split
    nidb.add_edges_from(edges_to_add, retain='edge_id')

    nidb.copy_graphics(g_graphics)

    return nidb
예제 #4
0
def compile_network(anm, hosts, ssh_pub_key = None ):
    nidb = NIDB()
    g_phy = anm['phy']
    g_ip = anm['ip']
    g_graphics = anm['graphics']
# TODO: build this on a platform by platform basis
    nidb.add_nodes_from(
        g_phy, retain=['label', 'host', 'platform', 'Network', 'update'])

    cd_nodes = [n for n in g_ip.nodes(
        "collision_domain") if not n.is_switch]  # Only add created cds - otherwise overwrite host of switched
    nidb.add_nodes_from(
        cd_nodes, retain=['label', 'host'], collision_domain=True)
# add edges to switches
    edges_to_add = [edge for edge in g_phy.edges()
            if edge.src.is_switch or edge.dst.is_switch]
    edges_to_add += [edge for edge in g_ip.edges() if edge.split] # cd edges from split
    nidb.add_edges_from(edges_to_add, retain='edge_id')

# TODO: boundaries is still a work in progress...
    nidb.copy_graphics(g_graphics)

    for target in hosts:
        try:
            target_data = config.settings['Hosts'][target]
        except KeyError:
            log.warning("Host %s not defined in configuration" % target)
            continue

        try:
            platform = target_data['platform']
        except KeyError:
            log.warning("no platform defined for %s" % target)
            continue
        shutil.rmtree(os.path.join("rendered", "%s_%s" % (target, platform)), ignore_errors=True)

        if platform == "netkit":
            platform_compiler = compiler.NetkitCompiler(nidb, anm, target, ssh_pub_key = ssh_pub_key)
        elif platform == "cisco":
            platform_compiler = compiler.CiscoCompiler(nidb, anm, target)
        elif platform == "dynagen":
            platform_compiler = compiler.DynagenCompiler(nidb, anm, target)
        elif platform == "junosphere":
            platform_compiler = compiler.JunosphereCompiler(nidb, anm, target)

        platform_compiler.compile()
        #if any(g_phy.nodes(host=target, platform=platform)): # this is really problematic
        #    log.info("Compile for %s on %s" % (platform, target))
        #    platform_compiler.compile()  # only compile if host set
        #else:
        #    log.debug("No devices set for %s on %s" % (platform, target))

    return nidb
예제 #5
0
파일: diff.py 프로젝트: matt-lee/autonetkit
def main():
    nidb_versions_dir = "../versions/nidb/"
    nidb_a = NIDB()
    #TODO: need to restore second latest, as may have changed tap ips since then
    previous_timestamp = 0
    while True:
        nidb_a.restore_latest(nidb_versions_dir)
        if nidb_a.timestamp == previous_timestamp:
            time.sleep(1)
        else:
            previous_timestamp = nidb_a.timestamp
            nidb_diffs = autonetkit.diff.nidb_diff(nidb_versions_dir)
            nidb_diff = nidb_diffs[0]

            print nidb_diff

            autonetkit.push_changes.apply_difference(nidb_a, nidb_diff)
예제 #6
0
파일: diff.py 프로젝트: geolykos/autonetkit
def main():
    nidb_versions_dir = "../versions/nidb/"
    nidb_a = NIDB()
#TODO: need to restore second latest, as may have changed tap ips since then
    previous_timestamp = 0
    while True:
        nidb_a.restore_latest(nidb_versions_dir)
        if nidb_a.timestamp == previous_timestamp:
            time.sleep(1)
        else:
            previous_timestamp = nidb_a.timestamp
            nidb_diffs = autonetkit.diff.nidb_diff(nidb_versions_dir)
            nidb_diff = nidb_diffs[0]

            print nidb_diff

            autonetkit.push_changes.apply_difference(nidb_a, nidb_diff)
예제 #7
0
def compile_network(anm):
    nidb = NIDB()
    g_phy = anm['phy']
    g_in=anm['input']
    g_ipv4 = anm['ipv4']
    g_graphics = anm['graphics']
# TODO: build this on a platform by platform basis
    nidb.add_nodes_from(
        g_in, retain=['label', 'host', 'platform', 'Network', 'update','level','domain','device_subtype','DNSResolver','device_type', 'name'])

    cd_nodes = [n for n in g_ipv4.nodes(
        "collision_domain") if not n.is_switch]  # Only add created cds - otherwise overwrite host of switched
    nidb.add_nodes_from(
        cd_nodes, retain=['label', 'host'], collision_domain=True)
# add edges to switches
    edges_to_add = [edge for edge in g_phy.edges(
    ) if edge.src.is_switch or edge.dst.is_switch]
    edges_to_add += [edge for edge in g_ipv4.edges(
    ) if edge.src.collision_domain or edge.dst.collision_domain]
    nidb.add_edges_from(edges_to_add, retain='edge_id')

# TODO: boundaries is still a work in progress...
    nidb.copy_graphics(g_graphics)

    for target, target_data in config.settings['Compile Targets'].items():
        host = target_data['host']
        platform = target_data['platform']
        if platform == "netkit":
            platform_compiler = compiler.NetkitCompiler(nidb, anm, host)
        elif platform == "cisco":
            platform_compiler = compiler.CiscoCompiler(nidb, anm, host)
        elif platform == "dynagen":
            platform_compiler = compiler.DynagenCompiler(nidb, anm, host)
        elif platform == "junosphere":
            platform_compiler = compiler.JunosphereCompiler(nidb, anm, host)

        if any(g_phy.nodes(host=host, platform=platform)):
            log.info("Compile for %s on %s" % (platform, host))
            platform_compiler.compile()  # only compile if hosts set
        else:
            log.debug("No devices set for %s on %s" % (platform, host))

    return nidb
예제 #8
0
def manage_network(input_graph_string, timestamp, build_options, reload_build=False, grid = None):
    """Build, compile, render network as appropriate"""
    # import build_network_simple as build_network
    import autonetkit.build_network as build_network
    if reload_build:
# remap?
        build_network = reload(build_network)

    messaging = ank_messaging.AnkMessaging()

    if build_options['build']:
        if input_graph_string:
            graph = build_network.load(input_graph_string)
        elif grid:
            graph = build_network.grid_2d(grid)

        anm = build_network.build(graph)
        if not build_options['compile']:
            # publish without nidb
            body = ank_json.dumps(anm)
            messaging.publish_compressed("www", "client", body)

    if build_options['compile']:
        if build_options['archive']:
            anm.save()
        nidb = compile_network(anm)
        body = ank_json.dumps(anm, nidb)
        messaging.publish_compressed("www", "client", body)
        log.debug("Sent ANM to web server")
        if build_options['archive']:
            nidb.save()
        # render.remove_dirs(["rendered"])
        if build_options['render']:
            render.render(nidb)

    if not(build_options['build'] or build_options['compile']):
        # Load from last run
        import autonetkit.anm
        anm = autonetkit.anm.AbstractNetworkModel()
        anm.restore_latest()
        nidb = NIDB()
        nidb.restore_latest()
        body = ank_json.dumps(anm, nidb)
        messaging.publish_compressed("www", "client", body)

    if build_options['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")
        with open("diff.json", "w") as fh:  # TODO: make file specified in config
            fh.write(data)

    # Note: this clobbers command line options
    # build_options.update(settings['General']) # update in case build has updated, eg for deploy
    # build_options.update(settings['General']) # update in case build has
    # updated, eg for deploy

    if build_options['deploy']:
        deploy_network(anm, nidb, input_graph_string)

    if build_options['measure']:
        measure_network(nidb)

    log.info("Finished")
예제 #9
0
def manage_network(input_graph_string,
                   timestamp,
                   build_options,
                   reload_build=False,
                   grid=None):
    """Build, compile, render network as appropriate"""
    # import build_network_simple as build_network
    import autonetkit.build_network as build_network
    if reload_build:
        # remap?
        build_network = reload(build_network)

    if build_options['build']:
        if input_graph_string:
            graph = build_network.load(input_graph_string)
        elif grid:
            graph = build_network.grid_2d(grid)

        anm = build_network.build(graph)
        if not build_options['compile']:
            update_http(anm)

        if build_options['validate']:
            import ank_validate
            ank_validate.validate(anm)

    if build_options['compile']:
        if build_options['archive']:
            anm.save()
        nidb = compile_network(anm)

        update_http(anm, nidb)
        log.debug("Sent ANM to web server")
        if build_options['archive']:
            nidb.save()
        # render.remove_dirs(["rendered"])
        if build_options['render']:
            render.render(nidb)

    if not (build_options['build'] or build_options['compile']):
        # Load from last run
        import autonetkit.anm
        anm = autonetkit.anm.AbstractNetworkModel()
        anm.restore_latest()
        nidb = NIDB()
        nidb.restore_latest()
        update_http(anm, nidb)

    if build_options['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")
        with open("diff.json",
                  "w") as fh:  # TODO: make file specified in config
            fh.write(data)

    # Note: this clobbers command line options
    # build_options.update(settings['General']) # update in case build has updated, eg for deploy
    # build_options.update(settings['General']) # update in case build has
    # updated, eg for deploy

    if build_options['deploy']:
        deploy_network(anm, nidb, input_graph_string)

    if build_options['measure']:
        measure_network(anm, nidb)

    log.info("Finished")
예제 #10
0
def create_nidb(anm):
    nidb = NIDB()
    g_phy = anm['phy']
    g_ip = anm['ip']
    g_graphics = anm['graphics']
    # TODO: build this on a platform by platform basis
    nidb.add_nodes_from(
        g_phy, retain=['label', 'host', 'platform', 'Network', 'update'])

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

    #TODO: write a helper functions to do this
    for node in nidb.nodes("collision_domain"):
        ipv4_node = anm['ipv4'].node(node)
        node.ipv4_subnet = ipv4_node.subnet
        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
    ]
    edges_to_add += [edge for edge in g_ip.edges()
                     if edge.split]  # cd edges from split
    nidb.add_edges_from(edges_to_add, retain='edge_id')

    # TODO: boundaries is still a work in progress...
    nidb.copy_graphics(g_graphics)

    return nidb
예제 #11
0
def create_nidb(anm):
    nidb = NIDB()
    g_phy = anm['phy']
    g_ip = anm['ip']
    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_ip.edges() if edge.split]
    nidb.add_edges_from(edges_to_add)

    nidb.copy_graphics(g_graphics)

    return nidb
예제 #12
0
        nidb = compile_network(anm)

        update_http(anm, nidb)
        log.debug("Sent ANM to web server")
        if build_options['archive']:
            nidb.save()
        # render.remove_dirs(["rendered"])
        if build_options['render']:
            render.render(nidb)

    if not(build_options['build'] or build_options['compile']):
        # Load from last run
        import autonetkit.anm
        anm = autonetkit.anm.AbstractNetworkModel()
        anm.restore_latest()
        nidb = NIDB()
        nidb.restore_latest()
        update_http(anm, nidb)

    if build_options['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)

    if build_options['deploy']:
        deploy_network(anm, nidb, input_graph_string)