Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
r1 = g_phy.node("r1")
r2 = g_phy.node("r2")
r3 = g_phy.node("r3")
r4 = g_phy.node("r4")
r5 = g_phy.node("r5")
r1.set("color", "blue")
result = [(n, n.get("color")) for n in g_phy]
expected_result = [(r4, None), (r5, None), (r1, 'blue'), (r2, None), (r3, None)]
self.assertListEqual(expected_result, result)
ank_utils.set_node_default(g_phy, color="red")
result = [(n, n.get("color")) for n in g_phy]
expected_result = [(r4, 'red'), (r5, 'red'), (r1, 'blue'), (r2, 'red'), (r3, 'red')]
self.assertListEqual(expected_result, result)
# Can also set for a specific bunch of nodes
nodes = ["r1", "r2", "r3"]
ank_utils.set_node_default(g_phy, nodes, role="core")
result = [(n, n.get("role")) for n in g_phy]
expected_result = [(r4, None), (r5, None), (r1, 'core'), (r2, 'core'), (r3, 'core')]
self.assertListEqual(expected_result, result)
result = [n.get("color") for n in g_phy]
expected_result = [None, None, None, None, None]
self.assertEqual(expected_result, result)
ank_utils.set_node_default(g_in, color="red")
ank_utils.copy_attr_from(g_in, g_phy, "color")
result = [n.get("color") for n in g_phy]
expected_result = ['red', 'red', 'red', 'red', 'red']
self.assertListEqual(expected_result, result)
# Can specify a default value if unset
nodes = ["r1", "r2", "r3"]
r1 = g_in.node('r1')
r2 = g_in.node('r2')
r3 = g_in.node('r3')
r4 = g_in.node('r4')
r5 = g_in.node('r5')
ank_utils.set_node_default(g_in, nodes, role="core")
ank_utils.copy_attr_from(g_in, g_phy, "role", default="edge")
result = [(n, n.get("role")) for n in g_phy]
expected_result = [(r4, 'edge'), (r5, 'edge'), (r1, 'core'),
(r2, 'core'), (r3, 'core')]
self.assertListEqual(expected_result, result)
# Can specify the remote attribute to set
ank_utils.copy_attr_from(g_in, g_phy, "role",
"device_role", default="edge")
result = [(n, n.get('device_role')) for n in g_phy]
expected_result = [(n, n.get('role') if n.get('role') else 'edge')
for n in g_in]
self.assertListEqual(expected_result, result)
# Can specify the type to cast to
g_in.update(memory = "32")
ank_utils.copy_attr_from(g_in, g_phy, "memory", type=int)
def test_set_node_default(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
r1 = g_phy.node("r1")
r2 = g_phy.node("r2")
r3 = g_phy.node("r3")
r4 = g_phy.node("r4")
r5 = g_phy.node("r5")
r1.set("color", "blue")
result = [(n, n.get("color")) for n in g_phy]
expected_result = [(r4, None), (r5, None), (r1, 'blue'), (r2, None), (r3, None)]
self.assertListEqual(expected_result, result)
ank_utils.set_node_default(g_phy, color="red")
result = [(n, n.get("color")) for n in g_phy]
expected_result = [(r4, 'red'), (r5, 'red'), (r1, 'blue'), (r2, 'red'), (r3, 'red')]
self.assertListEqual(expected_result, result)
# Can also set for a specific bunch of nodes
nodes = ["r1", "r2", "r3"]
ank_utils.set_node_default(g_phy, nodes, role="core")
result = [(n, n.get("role")) for n in g_phy]
expected_result = [(r4, None), (r5, None), (r1, 'core'), (r2, 'core'), (r3, 'core')]
self.assertListEqual(expected_result, result)
g_phy.data['vxlan_global_config'] = g_in.data['vxlan_global_config']
if g_phy.data.enable_routing is None:
g_in.data.enable_routing = True # default if not set
g_phy.add_nodes_from(g_in, retain=['name', 'label', 'update', 'device_type', 'devsubtype',
'asn', 'specified_int_names', 'x', 'y',
'device_subtype', 'platform', 'host', 'syntax',
'profile', 'syslog', 'vpc-peer',
'vxlan_vni_configured'])
if g_in.data.Creator == "Topology Zoo Toolset":
ank_utils.copy_attr_from(g_in, g_phy, "Network")
ank_utils.set_node_default(g_phy, Network=None)
g_phy.add_edges_from(g_in.edges(type="physical"), retain=['link_type'])
# TODO: make this automatic if adding to the physical graph?
ank_utils.set_node_default(g_phy, use_ipv4=False, use_ipv6=False)
ank_utils.copy_attr_from(g_in, g_phy, "custom_config_global",
dst_attr="custom_config")
for node in g_phy:
if node['input'].custom_config_loopback_zero:
lo_zero_config = node['input'].custom_config_loopback_zero
node.loopback_zero.custom_config = lo_zero_config
custom_config_phy_ints = node['input'].custom_config_phy_ints
for interface in node:
if custom_config_phy_ints:
interface.custom_config = custom_config_phy_ints
specified_id = interface['input'].get("specified_id")
build_ipv4(anm, infrastructure=False)
g_phy.update(g_phy, use_ipv4=False)
# TODO: Create collision domain overlay for ip addressing - l2 overlay?
if address_family == "None":
log.info("IP addressing disabled, not allocating IPv6")
anm.add_overlay("ipv6") # create empty so rest of code follows
g_phy.update(g_phy, use_ipv6=False)
elif address_family in ("v6", "dual_stack"):
build_ipv6(anm)
g_phy.update(g_phy, use_ipv6=True)
else:
anm.add_overlay("ipv6") # placeholder for compiler logic
default_igp = g_in.data.igp or "ospf"
ank_utils.set_node_default(g_in, igp=default_igp)
ank_utils.copy_attr_from(g_in, g_phy, "igp")
ank_utils.copy_attr_from(g_in, g_phy, "include_csr")
try:
from autonetkit_cisco import build_network as cisco_build_network
except ImportError, error:
log.debug("Unable to load autonetkit_cisco %s" % error)
else:
cisco_build_network.pre_design(anm)
# log.info("Building IGP")
from autonetkit.design.igp import build_igp
build_igp(anm)
# log.info("Building BGP")
g_phy.update(g_phy, use_ipv4=False)
# TODO: Create collision domain overlay for ip addressing - l2 overlay?
if address_family == "None":
log.info("IP addressing disabled, not allocating IPv6")
anm.add_overlay("ipv6") # create empty so rest of code follows
g_phy.update(g_phy, use_ipv6=False)
elif address_family in ("v6", "dual_stack"):
build_ipv6(anm)
g_phy.update(g_phy, use_ipv6=True)
else:
anm.add_overlay("ipv6") # placeholder for compiler logic
assign_loopback_ip_pool(anm)
#default_igp = g_in.data.igp or "ospf"
default_igp = g_in.data.igp
ank_utils.set_node_default(g_in, igp=default_igp)
ank_utils.copy_attr_from(g_in, g_phy, "igp")
ank_utils.copy_attr_from(g_in, g_phy, "include_csr")
try:
from autonetkit_cisco import build_network as cisco_build_network
except ImportError, error:
log.debug("Unable to load autonetkit_cisco %s" % error)
else:
cisco_build_network.pre_design(anm)
# log.info("Building IGP")
from autonetkit.design.igp import build_igp
build_igp(anm)
# log.info("Building BGP")
if g_in.data.vpcid_block:
g_phy.data['vpcid_block'] = g_in.data['vpcid_block']
if g_phy.data.enable_routing is None:
g_in.data.enable_routing = True # default if not set
g_phy.add_nodes_from(g_in, retain=['label', 'update', 'device_type', 'devsubtype',
'asn', 'specified_int_names', 'x', 'y',
'device_subtype', 'platform', 'host', 'syntax',
'profile', 'syslog'])
if g_in.data.Creator == "Topology Zoo Toolset":
ank_utils.copy_attr_from(g_in, g_phy, "Network")
ank_utils.set_node_default(g_phy, Network=None)
g_phy.add_edges_from(g_in.edges(type="physical"))
# TODO: make this automatic if adding to the physical graph?
ank_utils.set_node_default(g_phy, use_ipv4=False, use_ipv6=False)
ank_utils.copy_attr_from(g_in, g_phy, "custom_config_global",
dst_attr="custom_config")
for node in g_phy:
if node['input'].custom_config_loopback_zero:
lo_zero_config = node['input'].custom_config_loopback_zero
node.loopback_zero.custom_config = lo_zero_config
custom_config_phy_ints = node['input'].custom_config_phy_ints
for interface in node:
if custom_config_phy_ints:
interface.custom_config = custom_config_phy_ints
specified_id = interface['input'].get("specified_id")
build_ipv4(anm, infrastructure=False)
g_phy.update(g_phy, use_ipv4=False)
# TODO: Create collision domain overlay for ip addressing - l2 overlay?
if address_family == "None":
log.info("IP addressing disabled, not allocating IPv6")
anm.add_overlay("ipv6") # create empty so rest of code follows
g_phy.update(g_phy, use_ipv6=False)
elif address_family in ("v6", "dual_stack"):
build_ipv6(anm)
g_phy.update(g_phy, use_ipv6=True)
else:
anm.add_overlay("ipv6") # placeholder for compiler logic
default_igp = g_in.data.igp or "ospf"
ank_utils.set_node_default(g_in, igp=default_igp)
ank_utils.copy_attr_from(g_in, g_phy, "igp")
ank_utils.copy_attr_from(g_in, g_phy, "include_csr")
# log.info("Building IGP")
from autonetkit.design.igp import build_igp
build_igp(anm)
# log.info("Building BGP")
from autonetkit.design.bgp import build_bgp
build_bgp(anm)
# autonetkit.update_vis(anm)
from autonetkit.design.mpls import mpls_te, mpls_oam
mpls_te(anm)
mpls_oam(anm)
if g_phy.data.enable_routing is None:
g_in.data.enable_routing = True # default if not set
g_phy.add_nodes_from(g_in, retain=['label', 'update', 'device_type', 'devsubtype',
'asn', 'specified_int_names', 'x', 'y',
'device_subtype', 'platform', 'host', 'syntax',
'profile', 'syslog'])
if g_in.data.Creator == "Topology Zoo Toolset":
ank_utils.copy_attr_from(g_in, g_phy, "Network")
ank_utils.set_node_default(g_phy, Network=None)
g_phy.add_edges_from(g_in.edges(type="physical"))
# TODO: make this automatic if adding to the physical graph?
ank_utils.set_node_default(g_phy, use_ipv4=False, use_ipv6=False)
ank_utils.copy_attr_from(g_in, g_phy, "custom_config_global",
dst_attr="custom_config")
for node in g_phy:
if node['input'].custom_config_loopback_zero:
lo_zero_config = node['input'].custom_config_loopback_zero
node.loopback_zero.custom_config = lo_zero_config
custom_config_phy_ints = node['input'].custom_config_phy_ints
for interface in node:
if custom_config_phy_ints:
interface.custom_config = custom_config_phy_ints
specified_id = interface['input'].get("specified_id")
if specified_id:
interface.specified_id = specified_id # map across
#TODO: tidy this code up