Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test():
automated = True # whether to open ksdiff, log to file...
if __name__ == "__main__":
automated = False
dirname, filename = os.path.split(os.path.abspath(__file__))
parent_dir = os.path.abspath(os.path.join(dirname, os.pardir))
anm = autonetkit.NetworkModel()
input_file = os.path.join(parent_dir, "small_internet.graphml")
input_graph = graphml.load_graphml(input_file)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
try:
from websocket import create_connection
except ImportError:
print "websocket-client package not installed"
else:
autonetkit.update_http(anm)
ws = create_connection("ws://localhost:8000/ws")
ws.send("overlay_list")
automated = True # whether to open ksdiff, log to file...
enabled = False
if __name__ == "__main__":
# not called by test
automated = False
enabled = True
remote_server = "54.252.205.75"
if enabled:
dirname, filename = os.path.split(os.path.abspath(__file__))
input_file = os.path.join(dirname, "../big.graphml")
input_graph = graphml.load_graphml(input_file)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
render_hostname = "localhost"
nidb = console_script.create_nidb(anm)
import autonetkit.compilers.platform.netkit as pl_netkit
nk_compiler = pl_netkit.NetkitCompiler(nidb, anm, render_hostname)
nk_compiler.compile()
import autonetkit.render
autonetkit.render.render(nidb)
import autonetkit.deploy.netkit as nk_deploy
def build_anm(topology_name):
print "Building anm for %s" % topology_name
dirname, filename = os.path.split(os.path.abspath(__file__))
input_filename = os.path.join(dirname, "%s.graphml" % topology_name)
anm = autonetkit.NetworkModel()
input_graph = graphml.load_graphml(input_filename)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
return anm
import autonetkit.compilers.platform.netkit as pl_netkit
import os
import autonetkit.load.graphml as graphml
parse_template = pkg_resources.resource_filename("autonetkit", "textfsm/quagga/sh_ip_route")
emulation_server = "115.146.93.18"
anm = autonetkit.ANM()
anm.restore_latest()
nidb = autonetkit.DeviceModel()
nidb.restore_latest()
print list(nidb.nodes())
input_file = os.path.join("../../example/singleas.graphml")
input_graph = graphml.load_graphml(input_file)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
render_hostname = "localhost"
g_ospf = anm['ospf']
e1_8 = anm['ospf'].edge('5', '44')
print "before:", e1_8.cost
e1_8.cost = 1001
e1_8.apply_to_interfaces("cost")
print "after:", e1_8.cost
autonetkit.update_http(anm)
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': {
def build_overlays(filename):
anm = autonetkit.anm.AbstractNetworkModel()
input_graph = graphml.load_graphml(filename)
G_in = anm.add_overlay("input", graph = input_graph)
G_graphics = anm.add_overlay("graphics") # plotting data
G_graphics.add_nodes_from(G_in, retain=['x', 'y', 'device_type', 'asn'])
G_phy = anm['phy']
G_phy.add_nodes_from(G_in, retain=['label', 'device_type', 'asn', 'platform', 'host', 'syntax'])
G_phy.add_edges_from(G_in.edges(type="physical"))
G_phy.update(G_phy, syntax="quagga")
routers = list(G_in.routers())
G_ospf = anm.add_overlay("ospf", G_in.routers())
G_ospf.add_edges_from(e for e in G_in.edges() if e.src.asn == e.dst.asn)
G_ospf.update(area=0) # set defaults
G_ospf.update_edges(area=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': {
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:
input_graph = load_json.load_json(
input_graph_string, defaults=defaults)
return input_graph
template_names = set(node.pop_template for node in G_in)
template_names.discard("None")
template_names.discard(None)
if not len(template_names):
log.debug("No PoP templates set")
return # no templates set
# Load these templates
templates = {}
for template in template_names:
template_filename = os.path.join(
"pop_templates", "%s.graphml" % template)
try:
# TODO: pass in properties eg edge type = physical
pop_graph = autonetkit.load.graphml.load_graphml(template_filename)
except Exception, e:
log.warning("Unable to load pop template %s: %s" % (template, e))
return
# Undirected for now TODO: document this
pop_graph = pop_graph.to_undirected()
templates[template] = pop_graph
# construct new graph
G_out = nx.Graph() # TODO: what about bidirectional graphs?
G_out.add_nodes_from(expand_nodes(G, templates))
G_out.add_edges_from(intra_pop_links(G, templates))
G_out.add_edges_from(inter_pop_links(G, templates))
for s, t in G_out.edges():
G_out[s][t]['type'] = 'physical' # ensure copied across