Exemple #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")
Exemple #2
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_vis(anm)

        if build_options['validate']:
            import autonetkit.ank_validate
            try:
                autonetkit.ank_validate.validate(anm)
            except Exception, e:
                log.warning("Unable to validate topologies: %s" % e)
                log.debug("Unable to validate topologies", exc_info=True)
Exemple #3
0
def manage_network(input_graph_string, timestamp, build=True,
                   visualise=True, compile=True, validate=True, render=True,
                   monitor=False, deploy=False, measure=False, diff=False,
                   archive=False, grid=None, ):
    """Build, compile, render network as appropriate"""

    # import build_network_simple as build_network

    import autonetkit.build_network as build_network

    if build:
        if input_graph_string:
            graph = build_network.load(input_graph_string)
        elif grid:
            graph = build_network.grid_2d(grid)

        # TODO: integrate the code to visualise on error (enable in config)
        anm = None
        try:
            anm = build_network.build(graph)
        except Exception, e:
            # Send the visualisation to help debugging
            try:
                if visualise:
                    import autonetkit
                    autonetkit.update_vis(anm)
            except Exception, e:
                # problem with vis -> could be coupled with original exception -
                # raise original
                log.warning("Unable to visualise: %s" % e)
            raise  # raise the original exception
Exemple #4
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_vis(anm)

        if build_options['validate']:
            import autonetkit.ank_validate
            try:
                autonetkit.ank_validate.validate(anm)
            except Exception, e:
                log.warning("Unable to validate topologies: %s" % e)
                log.debug("Unable to validate topologies", exc_info=True)
def initialize(filename, defaults = True):
    from autonetkit.build_network import load, initialise
    with open(filename) as fh:
        data = fh.read()

    graph = load(data, defaults=defaults)
    anm = initialise(graph)
    return anm
Exemple #6
0
def initialize(filename, defaults=True):
    from autonetkit.build_network import load, initialise
    with open(filename) as fh:
        data = fh.read()

    graph = load(data, defaults=defaults)
    anm = initialise(graph)
    return anm
Exemple #7
0
def convert():
    filename = sys.argv[1]
    with open(filename, "r") as fh:
        data = fh.read()

    from autonetkit.build_network import build, load
    graph = load(data)
    anm = build(graph)

    import autonetkit
    g_in_nx = anm['input']._graph

    output = autonetkit.load.load_json.nx_to_simple(g_in_nx)
def convert():
    filename = sys.argv[1]
    with open(filename, "r") as fh:
        data = fh.read()

    from autonetkit.build_network import build, load
    graph = load(data)
    anm = build(graph)


    import autonetkit
    g_in_nx = anm['input']._graph

    output = autonetkit.load.load_json.nx_to_simple(g_in_nx)
Exemple #9
0
def manage_network(
    input_graph_string,
    timestamp,
    build=True,
    visualise=True,
    compile=True,
    validate=True,
    render=True,
    monitor=False,
    deploy=False,
    measure=False,
    diff=False,
    archive=False,
    grid=None,
):
    """Build, compile, render network as appropriate"""

    # import build_network_simple as build_network

    import autonetkit.build_network as build_network

    if build:
        if input_graph_string:
            graph = build_network.load(input_graph_string)
        elif grid:
            graph = build_network.grid_2d(grid)

        # TODO: integrate the code to visualise on error (enable in config)
        anm = None
        try:
            anm = build_network.build(graph)
        except Exception, e:
            # Send the visualisation to help debugging
            try:
                # if visualise:
                # import autonetkit
                # autonetkit.update_vis(anm)
                #TODO: refactor so only update if config or compile not both
                pass
            except Exception, e:
                # problem with vis -> could be coupled with original exception -
                # raise original
                log.warning("Unable to visualise: %s" % e)
            raise  # raise the original exception
Exemple #10
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")
Exemple #11
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")