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 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
def build(input_graph): """Main function to build network overlay topologies""" anm = None try: anm = initialise(input_graph) anm = apply_design_rules(anm) # print {str(node): {'x': node.x, 'y': node.y} for node in # anm['input']} autonetkit.update_vis(anm) except Exception, e: # Send the visualisation to help debugging try: 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)
def initialise(input_graph): """Initialises the input graph with from a NetworkX graph""" all_multigraph = input_graph.is_multigraph() anm = autonetkit.anm.NetworkModel(all_multigraph=all_multigraph) g_in = anm.initialise_input(input_graph) autonetkit.update_vis(anm) # set defaults if not g_in.data.specified_int_names: # if not specified then automatically assign interface names g_in.data.specified_int_names = False #import autonetkit.plugins.graph_product as graph_product # graph_product.expand(g_in) # apply graph products if relevant expand_fqdn = False # TODO: make this set from config and also in the input file if expand_fqdn and len(ank_utils.unique_attr(g_in, "asn")) > 1: # Multiple ASNs set, use label format device.asn anm.set_node_label(".", ['label', 'asn']) g_in.update(g_in.routers(platform="junosphere"), syntax="junos") g_in.update(g_in.routers(platform="dynagen"), syntax="ios") g_in.update(g_in.routers(platform="netkit"), syntax="quagga") # TODO: is this used? g_in.update(g_in.servers(platform="netkit"), syntax="quagga") autonetkit.ank.set_node_default(g_in, specified_int_names=None) g_graphics = anm.add_overlay("graphics") # plotting data g_graphics.add_nodes_from( g_in, retain=['x', 'y', 'device_type', 'label', 'device_subtype', 'asn']) if g_in.data.Creator == "VIRL": # TODO: move this to other module # Multiple ASNs set, use label format device.asn #anm.set_node_label(".", ['label_full']) pass return anm
def initialise(input_graph): """Initialises the input graph with from a NetworkX graph""" all_multigraph = input_graph.is_multigraph() anm = autonetkit.anm.NetworkModel(all_multigraph=all_multigraph) g_in = anm.initialise_input(input_graph) autonetkit.update_vis(anm) # set defaults if not g_in.data.specified_int_names: # if not specified then automatically assign interface names g_in.data.specified_int_names = False # import autonetkit.plugins.graph_product as graph_product # graph_product.expand(g_in) # apply graph products if relevant expand_fqdn = False # TODO: make this set from config and also in the input file if expand_fqdn and len(ank_utils.unique_attr(g_in, "asn")) > 1: # Multiple ASNs set, use label format device.asn anm.set_node_label(".", ["label", "asn"]) g_in.update(g_in.routers(platform="junosphere"), syntax="junos") g_in.update(g_in.routers(platform="dynagen"), syntax="ios") g_in.update(g_in.routers(platform="netkit"), syntax="quagga") # TODO: is this used? g_in.update(g_in.servers(platform="netkit"), syntax="quagga") autonetkit.ank.set_node_default(g_in, specified_int_names=None) g_graphics = anm.add_overlay("graphics") # plotting data g_graphics.add_nodes_from(g_in, retain=["x", "y", "device_type", "label", "device_subtype", "asn"]) if g_in.data.Creator == "VIRL": # TODO: move this to other module # Multiple ASNs set, use label format device.asn # anm.set_node_label(".", ['label_full']) pass return anm
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 else: if visualise: log.info("Visualising network") import autonetkit autonetkit.update_vis(anm) if not compile: #autonetkit.update_vis(anm) pass if 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) if compile:
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) 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)
#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 else: if visualise: # log.info("Visualising network") # import autonetkit # autonetkit.update_vis(anm) pass if not compile and visualise: autonetkit.update_vis(anm) pass if 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) if compile: if archive: anm.save() nidb = compile_network(anm) autonetkit.update_vis(anm, nidb)
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) 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)