Exemple #1
0
def load(input_graph_string, defaults=True):

    # TODO: look at XML header for file type
    import autonetkit.load.graphml as graphml
    import autonetkit.load.load_json as load_json
    try:
        input_graph = graphml.load_graphml(input_graph_string,
                                           defaults=defaults)
    except autonetkit.exception.AnkIncorrectFileFormat:
        try:
            input_graph = load_json.load_json(input_graph_string,
                                              defaults=defaults)
        except (ValueError, autonetkit.exception.AnkIncorrectFileFormat):
            # try a different reader
            try:
                from autonetkit_cisco import load as cisco_load
            except ImportError, error:
                log.debug("Unable to load autonetkit_cisco %s", error)
                return  # module not present (development module)
            else:
                input_graph = cisco_load.load(input_graph_string)
                # add local deployment host
                SETTINGS['General']['deploy'] = True
                SETTINGS['Deploy Hosts']['internal'] = {
                    'VIRL': {
                        'deploy': True,
                    },
                }
Exemple #2
0
def load(input_graph_string):
    # TODO: look at XML header for file type
    import autonetkit.load.graphml as graphml
    import autonetkit.load.load_json as load_json
    try:
        input_graph = graphml.load_graphml(input_graph_string)
    except autonetkit.exception.AnkIncorrectFileFormat:
        try:
            input_graph = load_json.load_json(input_graph_string)
        except (ValueError, autonetkit.exception.AnkIncorrectFileFormat):
            # try a different reader
            try:
                from autonetkit_cisco import load as cisco_load
            except ImportError, error:
                log.debug("Unable to load autonetkit_cisco %s", error)
                return  # module not present (development module)
            else:
                input_graph = cisco_load.load(input_graph_string)
                # add local deployment host
                SETTINGS['General']['deploy'] = True
                SETTINGS['Deploy Hosts']['internal'] = {
                    'VIRL': {
                        'deploy': True,
                    },
                }
Exemple #3
0
def load(input_graph_string):
    try:
        input_graph = graphml.load_graphml(input_graph_string)
    except autonetkit.exception.AnkIncorrectFileFormat:
        # try a different reader
        try:
            from autonetkit_cisco import load as cisco_load
        except ImportError:
            return  # module not present (development module)
        input_graph = cisco_load.load(input_graph_string)
        # add local deployment host
        SETTINGS["General"]["deploy"] = True
        SETTINGS["Deploy Hosts"]["internal"] = {"cisco": {"deploy": True}}

    return input_graph
Exemple #4
0
def load(input_graph_string):
    try:
        input_graph = graphml.load_graphml(input_graph_string)
    except autonetkit.exception.AnkIncorrectFileFormat:
# try a different reader
        try:
            from autonetkit_cisco import load as cisco_load
        except ImportError, e:
            log.debug("Unable to load autonetkit_cisco %s" % e)
            return  # module not present (development module)
        input_graph = cisco_load.load(input_graph_string)
# add local deployment host
        SETTINGS['General']['deploy'] = True
        SETTINGS['Deploy Hosts']['internal'] = {
            'cisco': {
            'deploy': True,
            },
        }
Exemple #5
0
def load(input_graph_string):
    try:
        input_graph = graphml.load_graphml(input_graph_string)
    except autonetkit.exception.AnkIncorrectFileFormat:
        # try a different reader
        try:
            from autonetkit_cisco import load as cisco_load
        except ImportError:
            return  # module not present (development module)
        input_graph = cisco_load.load(input_graph_string)
        # add local deployment host
        SETTINGS['General']['deploy'] = True
        SETTINGS['Deploy Hosts']['internal'] = {
            'cisco': {
                'deploy': True,
            },
        }

    return input_graph
def load(input_graph_string):
    # TODO: look at XML header for file type
    import autonetkit.load.graphml as graphml
    import autonetkit.load.load_json as load_json

    try:
        input_graph = graphml.load_graphml(input_graph_string)
    except autonetkit.exception.AnkIncorrectFileFormat:
        try:
            input_graph = load_json.load_json(input_graph_string)
        except autonetkit.exception.AnkIncorrectFileFormat:
            # try a different reader
            try:
                from autonetkit_cisco import load as cisco_load
            except ImportError, e:
                log.debug("Unable to load autonetkit_cisco %s" % e)
                return  # module not present (development module)
            else:
                input_graph = cisco_load.load(input_graph_string)
                # add local deployment host
                SETTINGS["General"]["deploy"] = True
                SETTINGS["Deploy Hosts"]["internal"] = {"VIRL": {"deploy": True}}
Exemple #7
0
def build(input_graph_string, timestamp):
    #TODO: move this out of main console wrapper
    anm = autonetkit.anm.AbstractNetworkModel()
    
    try:
        input_graph = graphml.load_graphml(input_graph_string)
    except autonetkit.exception.AnkIncorrectFileFormat:
# try a different reader
        try:
            from autonetkit_cisco import load as cisco_load
        except ImportError:
            return # module not present (development module)
        input_graph = cisco_load.load(input_graph_string)
# add local deployment host
        settings['General']['deploy'] = True
        settings['Deploy Hosts']['internal'] = {
                'cisco': {
                    'deploy': True,
                    },
                }

    #TODO: make this more explicit than overloading add_overlay - make it load_graph or something similar

#TODO: may need to revisit the collapse to a single directed graph: may need to consider link type, eg physical, when reducing directed to undirected graph
#Note: this may also require stripping edge specific information, such as IP addressing that only applies in one direction for a directed edge
    input_undirected = nx.Graph(input_graph)
    for node in input_graph:
        #del input_graph.node[node]['router config']
        #del input_graph.node[node]['device_subtype']
        pass
    #nx.write_graphml(input_graph, "output.graphml")
    G_in = anm.add_overlay("input", graph = input_undirected)
    G_in_directed = anm.add_overlay("input_directed", graph = input_graph, directed = True)

# set defaults
    if not G_in.data.specified_int_names:
        G_in.data.specified_int_names = False # if not specified then automatically assign interface names

    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.unique_attr(G_in, "asn")) > 1:
        # Multiple ASNs set, use label format device.asn 
        anm.set_node_label(".",  ['label', 'pop', 'asn'])

#TODO: remove, used for demo on nectar
    #for node in G_in:
        #node.platform = "netkit"
        #node.host = "nectar1"
    #G_in.data.igp = "ospf"

# set syntax for routers according to platform
#TODO: make these defaults
    G_in.update(G_in.nodes("is_router", platform = "junosphere"), syntax="junos")
    G_in.update(G_in.nodes("is_router", platform = "dynagen"), syntax="ios")
    G_in.update(G_in.nodes("is_router", platform = "netkit"), syntax="quagga")
    #G_in.update(G_in.nodes("is_router", platform = "cisco"), syntax="ios2")

    G_graphics = anm.add_overlay("graphics") # plotting data
    G_graphics.add_nodes_from(G_in, retain=['x', 'y', 'device_type', 'device_subtype', 'pop', 'asn'])

    build_phy(anm)
    #update_messaging(anm)
    #build_conn(anm)
    build_ip(anm)
    build_ip6(anm)
    
    igp = G_in.data.igp or "ospf" #TODO: make default template driven
#TODO: make the global igp be set on each node - this way can also support different IGPs per router

# Add overlays even if not used: simplifies compiler where can check for presence in overlay (if blank not present, don't configure ospf etc)
    anm.add_overlay("ospf")
    anm.add_overlay("isis")

    G_phy = anm['phy']
    ank.copy_attr_from(G_in, G_phy, "include_csr") #TODO: find more elegant passing method from input to compiler

    if igp == "ospf":
        build_ospf(anm)
    if igp == "isis":
        build_isis(anm)
    build_bgp(anm)

    #TODO: provide an ANM wide function that allocates interfaces
    #TODO: work out why some interfaces in bgp graph in vis have node data....
    for node in G_phy:
        for interface in node:
            interface.speed = 102

    return anm