コード例 #1
0
ファイル: console_script.py プロジェクト: backb1/autonetkit
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
ファイル: console_script.py プロジェクト: Rom2BE/autonetkit
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")
コード例 #3
0
ファイル: console_script.py プロジェクト: byouloh/autonetkit
                log.warning("Unable to validate topologies: %s" % e)
                log.debug("Unable to validate topologies", exc_info=True)


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

        update_vis(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.NetworkModel()
        anm.restore_latest()
        nidb = DeviceModel()
        nidb.restore_latest()
        update_vis(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)
コード例 #4
0
ファイル: console_script.py プロジェクト: matt-lee/autonetkit
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")
コード例 #5
0
def main():
    import argparse
    usage = "ank_measure_client"
    parser = argparse.ArgumentParser(description=usage)
    parser.add_argument('filename', default=None, help="Input topology")
    parser.add_argument('--deploy',
                        action="store_true",
                        default=False,
                        help="Deploy")
    parser.add_argument('--measure',
                        action="store_true",
                        default=False,
                        help="Measure")

    arguments = parser.parse_args()

    if arguments.filename:

        import build  # grabs build.py from example
        anm = build.build_overlays(arguments.filename)
        anm.save()

        import compile  # grabs compile.py from example
        nidb = build.build_nidb(anm)
        nidb.save()
        messaging = ank_messaging.AnkMessaging()
        messaging.publish_anm(anm, nidb)

        host = "localhost"
        nk_compiler = compile.NetkitCompiler(nidb, anm, host)
        nk_compiler.compile()

        render.render(nidb)
    else:
        log.info(
            "No input file specified, attempting to load previously compiled network"
        )
        # loading
        anm = autonetkit.anm.AbstractNetworkModel()
        anm.restore_latest()
        nidb = autonetkit.nidb.NIDB()
        nidb.restore_latest()

    username = "******"
    host = "192.168.255.129"
    if arguments.deploy:
        import autonetkit.deploy.netkit as nk_deploy
        dst_folder = nidb.topology['localhost'].render_dst_folder
        nk_deploy.deploy(host, username, dst_folder)

    if arguments.measure:
        """ Some notes on measurement:
        NOTE: Measure requires a remote host to be setup, and rabbitmq running, (by default ank will look on localhost)
 http://www.rabbitmq.com/install-debian.html

 or for OS X: http://superuser.com/questions/464311/open-port-5672-tcp-for-access-to-rabbitmq-on-mac

 and
 pip install pika
 pip install https://github.com/knipknap/exscript/tarball/master
 note this needs paramiko... which needs to compile. if you don't have python headers, eg in ubuntu: sudo apt-get install python-dev
 wget https://raw.github.com/sk2/autonetkit/master/autonetkit/measure_client.py
 sk2@ubuntu:~$ python measure_client.py --server 192.168.255.1
 where --server specifies the rabbitmq server
 can also use through ANK package:
 install ank through github, then install Exscript
 can then do:
 ank_measure_client --server 192.168.255.1
"""

        import autonetkit.measure as measure
        log.info("Measuring network")
        remote_hosts = [node.tap.ip for node in nidb.routers()]
        #remote_hosts = remote_hosts[:3] # truncate for testing
        dest_node = random.choice(list(nidb.routers()))
        log.info("Tracing to randomly selected node: %s" % dest_node)
        dest_ip = dest_node.interfaces[
            0].ipv4_address  # choose random interface on this node
        command = "traceroute -n -a -U -w 0.5 %s" % dest_ip
        #command = 'vtysh -c "show ip route"'
        measure.send(nidb, command, remote_hosts, threads=20)

        # abort after 10 fails, proceed on any success, 0.1 second timeout (quite aggressive)
        #command = 'vtysh -c "show ip route"'
        remote_hosts = [
            node.tap.ip for node in nidb.routers() if node.bgp.ebgp_neighbors
        ]
        command = "cat /var/log/zebra/bgpd.log"
コード例 #6
0
ファイル: console_script.py プロジェクト: Rom2BE/autonetkit
def main():
    import argparse
    usage = "ank_measure_client"
    parser = argparse.ArgumentParser(description = usage)
    parser.add_argument('filename',  default= None, help="Input topology")   
    parser.add_argument('--deploy',  action="store_true", default= False, help="Deploy")        
    parser.add_argument('--measure',  action="store_true", default= False, help="Measure")        
    
    arguments = parser.parse_args()

    if arguments.filename:

        import build # grabs build.py from example
        anm = build.build_overlays(arguments.filename)
        anm.save()

        import compile # grabs compile.py from example
        nidb = build.build_nidb(anm)
        nidb.save()
        messaging = ank_messaging.AnkMessaging()
        messaging.publish_anm(anm, nidb)

        host = "localhost"
        nk_compiler = compile.NetkitCompiler(nidb, anm, host)
        nk_compiler.compile()

        render.render(nidb)
    else:
        log.info("No input file specified, attempting to load previously compiled network")
        # loading
        anm = autonetkit.anm.AbstractNetworkModel()
        anm.restore_latest()
        nidb = autonetkit.nidb.NIDB()
        nidb.restore_latest()

    username = "******"
    host = "192.168.255.129"
    if arguments.deploy:
        import autonetkit.deploy.netkit as nk_deploy
        dst_folder = nidb.topology['localhost'].render_dst_folder
        nk_deploy.deploy(host, username, dst_folder)
    
    if arguments.measure:
        """ Some notes on measurement:
        NOTE: Measure requires a remote host to be setup, and rabbitmq running, (by default ank will look on localhost)
 http://www.rabbitmq.com/install-debian.html

 or for OS X: http://superuser.com/questions/464311/open-port-5672-tcp-for-access-to-rabbitmq-on-mac

 and
 pip install pika
 pip install https://github.com/knipknap/exscript/tarball/master
 note this needs paramiko... which needs to compile. if you don't have python headers, eg in ubuntu: sudo apt-get install python-dev
 wget https://raw.github.com/sk2/autonetkit/master/autonetkit/measure_client.py
 sk2@ubuntu:~$ python measure_client.py --server 192.168.255.1
 where --server specifies the rabbitmq server
 can also use through ANK package:
 install ank through github, then install Exscript
 can then do:
 ank_measure_client --server 192.168.255.1
"""

        import autonetkit.measure as measure
        log.info("Measuring network")
        remote_hosts = [node.tap.ip for node in nidb.routers() ]
        #remote_hosts = remote_hosts[:3] # truncate for testing
        dest_node = random.choice(list(nidb.routers()))
        log.info("Tracing to randomly selected node: %s" % dest_node)
        dest_ip = dest_node.interfaces[0].ipv4_address # choose random interface on this node
        command = "traceroute -n -a -U -w 0.5 %s" % dest_ip 
        #command = 'vtysh -c "show ip route"'
        measure.send(nidb, command, remote_hosts, threads = 20)

        # abort after 10 fails, proceed on any success, 0.1 second timeout (quite aggressive)
        #command = 'vtysh -c "show ip route"'
        remote_hosts = [node.tap.ip for node in nidb.routers() if node.bgp.ebgp_neighbors]
        command = "cat /var/log/zebra/bgpd.log"
コード例 #7
0
                autonetkit.ank_validate.validate(anm)
            except Exception, e:
                log.warning("Unable to validate topologies: %s" % e)

    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)