autonetkit package

Subpackages

Submodules

autonetkit.ank module

autonetkit.ank.aggregate_nodes(nm_graph, nodes, retain=None)

Combines connected into a single node

autonetkit.ank.boundary_nodes(nm_graph, nodes)

returns nodes at boundary of G based on edge_boundary from networkx

autonetkit.ank.connected_subgraphs(nm_graph, nodes=None)
>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> connected_subgraphs(g_phy)
[[r4, r5, r1, r2, r3]]
>>> edges = [("r2", "r4"), ("r3", "r5")]
>>> g_phy.remove_edges_from(edges)
>>> connected_subgraphs(g_phy)
[[r1, r2, r3], [r4, r5]]
autonetkit.ank.copy_attr_from(overlay_src, overlay_dst, src_attr, dst_attr=None, nbunch=None, type=None, default=None)
>>> anm = autonetkit.topos.house()
>>> g_in = anm['input']
>>> g_phy = anm['phy']
>>> [n.color for n in g_phy]
[None, None, None, None, None]
>>> set_node_default(g_in, color="red")
>>> copy_attr_from(g_in, g_phy, "color")
>>> [n.color for n in g_phy]
['red', 'red', 'red', 'red', 'red']

Can specify a default value if unset

>>> nodes = ["r1", "r2", "r3"]
>>> set_node_default(g_in, nodes, role="core")
>>> copy_attr_from(g_in, g_phy, "role", default="edge")
>>> [(n, n.role) for n in g_phy]
[(r4, 'edge'), (r5, 'edge'), (r1, 'core'), (r2, 'core'), (r3, 'core')]

Can specify the remote attribute to set

>>> copy_attr_from(g_in, g_phy, "role", "device_role", default="edge")

Can specify the type to cast to

>>> g_in.update(memory = "32")
>>> copy_attr_from(g_in, g_phy, "memory", type=int)
>>> [n.memory for n in g_phy]
[32, 32, 32, 32, 32]

Supported types to case to are float and int

autonetkit.ank.copy_edge_attr_from(overlay_src, overlay_dst, src_attr, dst_attr=None, type=None, default=None)
autonetkit.ank.copy_int_attr_from(overlay_src, overlay_dst, src_attr, dst_attr=None, nbunch=None, type=None, default=None)
>>> anm = autonetkit.topos.house()
>>> g_in = anm['input']
>>> g_phy = anm['phy']
>>> [iface.ospf_cost for node in g_phy for iface in node]
[None, None, None, None, None, None, None, None, None, None, None, None]
>>> for node in g_in:
...      for interface in node:
...         interface.ospf_cost = 10
>>> copy_int_attr_from(g_in, g_phy, "ospf_cost")
>>> [iface.ospf_cost for node in g_phy for iface in node]
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]

Supported types to case to are float and int

autonetkit.ank.explode_nodes(nm_graph, nodes, retain=None)

Explodes all nodes in nodes TODO: explain better TODO: Add support for digraph - check if nm_graph.is_directed()

>>> anm = autonetkit.topos.mixed()
>>> g_phy = anm['phy']
>>> switches = g_phy.switches()
>>> exploded_edges = explode_nodes(g_phy, switches)
>>> exploded_edges
[(r1, r2)]

Or to explode a specific node

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> g_phy.nodes()
[r4, r5, r1, r2, r3]
>>> sorted(g_phy.edges())
[(r1, r2), (r1, r3), (r2, r3), (r4, r2), (r4, r5), (r5, r3)]
>>> r2 = g_phy.node("r2")
>>> exploded_edges = explode_nodes(g_phy, r2)
>>> exploded_edges
[(r1, r4), (r3, r4), (r1, r3)]
>>> g_phy.nodes()
[r4, r5, r1, r3]
>>> sorted(g_phy.edges())
[(r1, r3), (r4, r1), (r4, r3), (r4, r5), (r5, r3)]
autonetkit.ank.fqdn(node)

Example:

>>> anm = autonetkit.topos.house()
>>> r1 = anm['phy'].node("r1")
>>> fqdn(r1)
'r1.1'
autonetkit.ank.groupby(attribute, nodes)

Takes a group of nodes and returns a generator of (attribute, nodes) for each attribute value A simple wrapped around itertools.groupby that creates a lambda for the attribute

autonetkit.ank.in_edges(nm_graph, nodes=None)
autonetkit.ank.label(nm_graph, nodes)
autonetkit.ank.most_frequent(iterable)

returns most frequent item in iterable

autonetkit.ank.name_folder_safe(foldername)
autonetkit.ank.neigh_attr(nm_graph, node, attribute, attribute_graph=None)

TODO: tidy up parameters to take attribute_graph first, and then evaluate if attribute_graph set, if not then use attribute_graph as attribute explain how nm_graph and attribute_graph work, eg for G_ip and G_phy

autonetkit.ank.neigh_average(nm_graph, node, attribute, attribute_graph=None)

averages out attribute from neighbors in specified nm_graph attribute_graph is the graph to read the attribute from if property is numeric, then return mean else return most frequently occuring value

autonetkit.ank.neigh_equal(nm_graph, node, attribute, attribute_graph=None)

Boolean, True if neighbors in nm_graph all have same attribute in attribute_graph

autonetkit.ank.neigh_most_frequent(nm_graph, node, attribute, attribute_graph=None, allow_none=False)

Used to explicitly force most frequent - useful if integers such as ASN which would otherwise return mean

autonetkit.ank.set_node_default(nm_graph, nbunch=None, **kwargs)

Sets all nodes in nbunch to value if key not already set Note: this won’t apply to future nodes added

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> r1 = g_phy.node("r1")
>>> r1.color = "blue"
>>> [(n, n.color) for n in g_phy]
[(r4, None), (r5, None), (r1, 'blue'), (r2, None), (r3, None)]
>>> set_node_default(g_phy, color="red")
>>> [(n, n.color) for n in g_phy]
[(r4, 'red'), (r5, 'red'), (r1, 'blue'), (r2, 'red'), (r3, 'red')]

Can also set for a specific bunch of nodes

>>> nodes = ["r1", "r2", "r3"]
>>> set_node_default(g_phy, nodes, role="core")
>>> [(n, n.role) for n in g_phy]
[(r4, None), (r5, None), (r1, 'core'), (r2, 'core'), (r3, 'core')]
autonetkit.ank.shallow_copy_nx_graph(nx_graph)

Convenience wrapper for nx shallow copy

>>> import networkx
>>> G = nx.Graph()
>>> H = shallow_copy_nx_graph(G)
>>> isinstance(H, nx.Graph)
True
>>> isinstance(H, nx.DiGraph)
False
>>> isinstance(H, nx.MultiGraph)
False
>>> isinstance(H, nx.MultiDiGraph)
False
>>> G = nx.DiGraph()
>>> H = shallow_copy_nx_graph(G)
>>> isinstance(H, nx.DiGraph)
True
>>> G = nx.MultiGraph()
>>> H = shallow_copy_nx_graph(G)
>>> isinstance(H, nx.MultiGraph)
True
>>> G = nx.MultiDiGraph()
>>> H = shallow_copy_nx_graph(G)
>>> isinstance(H, nx.MultiDiGraph)
True
autonetkit.ank.shortest_path(nm_graph, src, dst)
autonetkit.ank.sn_preflen_to_network(address, prefixlen)

Workaround for creating an IPNetwork from an address and a prefixlen TODO: check if this is part of netaddr module

autonetkit.ank.split(nm_graph, edges, retain=None, id_prepend='')

Splits edges in two, retaining any attributes specified.

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> edge = g_phy.edge("r1", "r2")
>>> new_nodes = split(g_phy, edge)
>>> new_nodes
[r1_r2]
>>> [n.neighbors() for n in new_nodes]
[[r1, r2]]

For multiple edges and specifying a prepend for the new nodes

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> edges = g_phy.node("r2").edges()
>>> new_nodes = split(g_phy, edges, id_prepend="split_")
>>> new_nodes
[split_r2_r4, split_r1_r2, split_r2_r3]
>>> [n.neighbors() for n in new_nodes]
[[r4, r2], [r1, r2], [r2, r3]]
class autonetkit.ank.static_route_v4(prefix, netmask, nexthop, metric)

Bases: tuple

metric

Alias for field number 3

netmask

Alias for field number 1

nexthop

Alias for field number 2

prefix

Alias for field number 0

class autonetkit.ank.static_route_v6(prefix, nexthop, metric)

Bases: tuple

metric

Alias for field number 2

nexthop

Alias for field number 1

prefix

Alias for field number 0

autonetkit.ank.unique_attr(nm_graph, attribute)
autonetkit.ank.wrap_edges(nm_graph, edges)

wraps edge ids into edge overlay

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> elist = [("r1", "r2"), ("r2", "r3")]
>>> edges = wrap_edges(g_phy, elist)

The edges are now NetworkModel edge objects

>>> edges
[(r1, r2), (r2, r3)]
autonetkit.ank.wrap_nodes(nm_graph, nodes)

wraps node id into node overlay

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> nlist = ["r1", "r2", "r3"]
>>> nodes = wrap_nodes(g_phy, nlist)

The nodes are now NetworkModel node objects

>>> nodes
[r1, r2, r3]

This is generally used in internal functions. An alternative method is:

>>> [g_phy.node(n) for n in nlist]
[r1, r2, r3]

autonetkit.ank_json module

class autonetkit.ank_json.AnkEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)

Bases: json.encoder.JSONEncoder

Handles netaddr objects by converting to string form

default(obj)
autonetkit.ank_json.ank_json_custom_loads(data)
autonetkit.ank_json.ank_json_dumps(graph, indent=4)
autonetkit.ank_json.ank_json_loads(data)
autonetkit.ank_json.dumps(anm, nidb=None, indent=4)
autonetkit.ank_json.jsonify_anm(anm)

Returns a dictionary of json-ified overlay graphs

autonetkit.ank_json.jsonify_anm_with_graphics(anm, nidb=None)

Returns a dictionary of json-ified overlay graphs, with graphics data appended to each overlay

autonetkit.ank_json.jsonify_nidb(nidb)
autonetkit.ank_json.prepare_nidb(nidb)
autonetkit.ank_json.rebind_interfaces(anm)
autonetkit.ank_json.rebind_nidb_interfaces(nidb)
autonetkit.ank_json.restore_anm_nidb_from_json(data)
autonetkit.ank_json.shortened_interface(name)

Condenses interface name. Not canonical - mainly for brevity

autonetkit.ank_json.string_to_netaddr(val)

autonetkit.ank_messaging module

autonetkit.ank_messaging.format_http_url(host=None, port=None, route='publish')
autonetkit.ank_messaging.get_uuid(anm)
autonetkit.ank_messaging.highlight(nodes=None, edges=None, paths=None, path=None, uuid='singleuser', http_url=None)
autonetkit.ank_messaging.update_vis(anm=None, nidb=None, http_url=None, uuid=None)

autonetkit.ank_utils module

AutoNetkit Utilities

autonetkit.ank_utils.alphabetical_sort(l)

From http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python

autonetkit.ank_utils.call_log(fn, *args, **kwargs)
autonetkit.ank_utils.merge_quagga_conf()
autonetkit.ank_utils.unwrap_edges(edges)

Unwrap edges

autonetkit.ank_utils.unwrap_graph(nm_graph)

Unwrap graph

autonetkit.ank_utils.unwrap_nodes(nodes)

Unwrap nodes

autonetkit.ank_utils.wrap_nodes(nm_graph, nodes)

wraps node id into node overlay

autonetkit.ank_validate module

autonetkit.ank_validate.all_nodes_have_asn(anm)
autonetkit.ank_validate.all_same(items)
autonetkit.ank_validate.all_unique(items)
autonetkit.ank_validate.check_for_selfloops(anm)
autonetkit.ank_validate.duplicate_items(items)
autonetkit.ank_validate.validate(anm)
autonetkit.ank_validate.validate_ibgp(anm)
autonetkit.ank_validate.validate_igp(anm)
autonetkit.ank_validate.validate_ipv4(anm)

autonetkit.anm module

autonetkit.build_network module

Module to build overlay graphs for network design

autonetkit.build_network.build(input_graph)

Main function to build network overlay topologies

autonetkit.compiler module

autonetkit.compiler.dot_to_underscore(instring)

Replace dots with underscores

autonetkit.compiler.natural_sort(sequence, key=<function <lambda>>)

Sort the sequence into natural alphanumeric order.

autonetkit.compiler.sort_sessions(sequence)

Wrapper around natural_sort for bgp sessions

autonetkit.config module

autonetkit.config.load_config()

autonetkit.console_script module

Console script entry point for AutoNetkit

autonetkit.console_script.console_entry()

If come from console entry point

autonetkit.console_script.main(options)
autonetkit.console_script.parse_options(argument_string=None)

Parse user-provided options

autonetkit.diff module

autonetkit.diff.compare(graph_a, graph_b)
autonetkit.diff.compare_nidb(nidb_a, nidb_b)
autonetkit.diff.elem_diff(elem_a, elem_b)
autonetkit.diff.nidb_diff(directory=None, length=1)

autonetkit.example module

autonetkit.example.house()

Returns anm with input and physical as house graph

autonetkit.exception module

exception autonetkit.exception.AnkIncorrectFileFormat

Bases: autonetkit.exception.AutoNetkitException

Wrong file format

exception autonetkit.exception.AutoNetkitException

Bases: exceptions.Exception

Base class for AutoNetkit Exceptions

exception autonetkit.exception.OverlayNotFound(errors)

Bases: autonetkit.exception.AutoNetkitException

autonetkit.log module

class autonetkit.log.CustomAdapter(logger, extra)

Bases: logging.LoggerAdapter

process(msg, kwargs)

autonetkit.render module

autonetkit.render.format_version_banner()
autonetkit.render.initialise_lookup()
autonetkit.render.render(nidb)
autonetkit.render.render_inline(node, render_template_file, to_memory=True, render_dst_file=None)

Generic rendering of a node attribute rather than the standard location. Needs to be called by render_node. Doesn’t support base folders - only single attributes. Note: supports rendering to memory (ie back to nidb rather than file)

autonetkit.render.render_node(node)
autonetkit.render.render_single(nidb)
autonetkit.render.render_topologies(nidb)
autonetkit.render.render_topology(topology)
autonetkit.render.resource_path(relative)

Makes relative to package

autonetkit.webserver module

class autonetkit.webserver.AnkAccessor(maxlen=25, simplified_overlays=False)

Used to store published topologies

get_overlay(uuid, overlay_id)
ip_allocations()
overlay_list(uuid)
store_overlay(uuid, overlay_input)
class autonetkit.webserver.IndexHandler(application, request, **kwargs)

Bases: tornado.web.RequestHandler

Used to treat index.html as a template and substitute the uuid parameter for the websocket call

get()
initialize(path)
class autonetkit.webserver.MyWebHandler(application, request, **kwargs)

Bases: tornado.web.RequestHandler

get()
initialize(ank_accessor, singleuser_mode=False)
post()
class autonetkit.webserver.MyWebSocketHandler(application, request, **kwargs)

Bases: tornado.websocket.WebSocketHandler

allow_draft76()
initialize(ank_accessor, overlay_id, singleuser_mode=False)

Store the overlay_id this listener is currently viewing. Used when updating.

on_close()
on_message(message)
open(*args, **kwargs)
update_overlay()
autonetkit.webserver.main()

autonetkit.yaml_utils module

autonetkit.yaml_utils.add_representers()
class autonetkit.yaml_utils.literal

Bases: str

autonetkit.yaml_utils.literal_presenter(dumper, data)
autonetkit.yaml_utils.ordered_dict_presenter(dumper, data)
class autonetkit.yaml_utils.quoted

Bases: str

autonetkit.yaml_utils.quoted_presenter(dumper, data)

Module contents