コード例 #1
0
ファイル: console_script.py プロジェクト: sk2/ANK-NG
def compile_network(anm):
    nidb = NIDB() 
    G_phy = anm.overlay.phy
    G_ip = anm.overlay.ip
    G_graphics = anm.overlay.graphics
#TODO: build this on a platform by platform basis
    nidb.add_nodes_from(G_phy, retain=['label', 'host', 'platform'])

    nidb.add_nodes_from(G_ip.nodes("collision_domain"), 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.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...
    for node in nidb:
        graphics_node = G_graphics.node(node)
        node.graphics.x = graphics_node.x
        node.graphics.y = graphics_node.y
        node.graphics.device_type = graphics_node.device_type
        node.device_type = graphics_node.device_type

    host = "nectar1"
    #junosphere_compiler = compiler.JunosphereCompiler(nidb, anm, host)
    #junosphere_compiler.compile()
    netkit_compiler = compiler.NetkitCompiler(nidb, anm, host)
    netkit_compiler.compile()
    #dynagen_compiler = compiler.DynagenCompiler(nidb, anm, host)
    #dynagen_compiler.compile()

    #cisco_compiler = compiler.CiscoCompiler(nidb, anm, host)
    #cisco_compiler.compile()

    return nidb
コード例 #2
0
ファイル: console_script.py プロジェクト: wilko77/STRIP
def compile_network(anm):
    nidb = NIDB() 
    G_phy = anm.overlay.phy
    G_ip = anm.overlay.ip
    G_graphics = anm.overlay.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.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)

    #junosphere_compiler = compiler.JunosphereCompiler(nidb, anm, host)
    #junosphere_compiler.compile()
    #host = "nectar1"
    #netkit_compiler = compiler.NetkitCompiler(nidb, anm, host)
    #netkit_compiler.compile()

    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)

        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
コード例 #3
0
def compile_network(anm):
    nidb = NIDB()
    G_phy = anm.overlay.phy
    G_ip = anm.overlay.ip
    G_graphics = anm.overlay.graphics
    #TODO: build this on a platform by platform basis
    nidb.add_nodes_from(G_phy, retain=['label', 'host', 'platform'])

    nidb.add_nodes_from(G_ip.nodes("collision_domain"),
                        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.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...
    for node in nidb:
        graphics_node = G_graphics.node(node)
        node.graphics.x = graphics_node.x
        node.graphics.y = graphics_node.y
        node.graphics.device_type = graphics_node.device_type
        node.device_type = graphics_node.device_type

    host = "nectar1"
    #junosphere_compiler = compiler.JunosphereCompiler(nidb, anm, host)
    #junosphere_compiler.compile()
    netkit_compiler = compiler.NetkitCompiler(nidb, anm, host)
    netkit_compiler.compile()
    #dynagen_compiler = compiler.DynagenCompiler(nidb, anm, host)
    #dynagen_compiler.compile()

    #cisco_compiler = compiler.CiscoCompiler(nidb, anm, host)
    #cisco_compiler.compile()

    return nidb
コード例 #4
0
ファイル: console_script.py プロジェクト: coana/ank_v3_dev
def main():
    ank_version = pkg_resources.get_distribution("AutoNetkit").version
    log.info("AutoNetkit %s" % ank_version)

    import optparse
    opt = optparse.OptionParser()
    opt.add_option('--file', '-f', default= None, help="Load topology from FILE")        
    opt.add_option('--monitor', '-m',  action="store_true", default= False, help="Monitor input file for changes")        
    opt.add_option('--debug',  action="store_true", default= False, help="Debug mode")        
    opt.add_option('--compile',  action="store_true", default= False, help="Compile")        
    opt.add_option('--deploy',  action="store_true", default= False, help="Deploy")        
    opt.add_option('--measure',  action="store_true", default= False, help="Measure")        
    options, arguments = opt.parse_args()

    input_filename = options.file
    if not options.file:
        input_filename = "ank.graphml"

    if options.debug:
        #TODO: fix this
        import logging
        logger = logging.getLogger("ANK")
        logger.setLevel(logging.DEBUG)

    if options.compile:
        anm = build_network(input_filename)
        anm.save()
        nidb = compile_network(anm)
        nidb.save()
        render.remove_dirs(["rendered/nectar1/nklab/"])
        render.render(nidb)
    else:
        anm = AbstractNetworkModel()
        anm.restore_latest()
        nidb = NIDB()
        nidb.restore_latest()

    if options.deploy:
        deploy_network(nidb)
    if options.measure:
        measure_network(nidb)

    if options.monitor:
        try:
            log.info("Monitoring for updates...")
            while True:
                time.sleep(0.2)
                if change_monitor.check_for_change(input_filename, anm):
                    try:
                        log.info("Input graph updated, recompiling network")
                        if options.compile:
                            nidb = compile_network(anm)
                            render.remove_dirs(["rendered/nectar1/nklab/"])
                            render.render(nidb)
                        if options.deploy:
                            deploy_network(nidb)
                        if options.measure:
                            measure_network(nidb)
                        log.info("Monitoring for updates...")
                    except:
                        # TODO: remove this, add proper warning
                        log.warn("Unable to build network")
                        pass
        except KeyboardInterrupt:
            log.info("Exiting")
コード例 #5
0
ファイル: console_script.py プロジェクト: wilko77/STRIP
def manage_network(input_graph_string, timestamp, build_options, reload_build=False):
    #import build_network_simple as build_network
    import build_network
    if reload_build:
# remap?
        build_network = reload(build_network)
    settings = config.settings

    rabbitmq_server = settings['Rabbitmq']['server']
    messaging = ank_messaging.AnkMessaging(rabbitmq_server)


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

    if build_options['compile']:
        if build_options['archive']:
            anm.save()
        nidb = compile_network(anm)
        import autonetkit.ank_json
        body = autonetkit.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 = autonetkit.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 ank_json
        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(nidb, input_graph_string)

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