def lab_topology(self): host_nodes = self.nidb.nodes(host=self.host) # TODO: replace name/label and use attribute from subgraph lab_topology = self.nidb.topology[self.host] lab_topology.render_template = "templates/netkit_lab_conf.mako" lab_topology.render_dst_folder = "rendered/%s/%s" % (self.host, "nklab") lab_topology.render_dst_file = "lab.conf" subgraph = self.nidb.subgraph(host_nodes, self.host) lab_topology.description = "AutoNetkit Lab" lab_topology.author = "AutoNetkit" lab_topology.web = "www.autonetkit.org" lab_topology.machines = " ".join( sorted(naming.network_hostname(phy_node) for phy_node in subgraph.nodes("is_l3device")) ) G_ip = self.anm["ip"] config_items = [] for node in subgraph.nodes("is_l3device"): for edge in node.edges(): collision_domain = str(G_ip.edge(edge).dst.subnet).replace("/", ".") numeric_id = edge.id.replace("eth", "") # netkit lab.conf uses 1 instead of eth1 config_items.append( {"device": naming.network_hostname(node), "key": numeric_id, "value": collision_domain} ) tap_ips = [] for node in subgraph: if node.tap: tap_ips.append({"device": naming.network_hostname(node), "id": node.tap.id, "ip": node.tap.ip}) # TODO: include ram, etc from here lab_topology.config_items = sort_attribute(config_items, "device") lab_topology.tap_ips = sort_attribute(tap_ips, "device")
def lab_topology(self): #TODO: replace name/label and use attribute from subgraph lab_topology = self.nidb.topology[self.host] lab_topology.render_template = "templates/netkit_lab_conf.mako" lab_topology.render_dst_folder = "rendered/%s/%s" % (self.host, "netkit") lab_topology.render_dst_file = "lab.conf" lab_topology.description = "AutoNetkit Lab" lab_topology.author = "AutoNetkit" lab_topology.web = "www.autonetkit.org" host_nodes = list(self.nidb.nodes(host=self.host, platform="netkit")) if not len(host_nodes): log.debug("No Netkit hosts for %s" % self.host) #TODO: make so can return here #return # also need collision domains for this host cd_nodes = self.nidb.nodes( "collision_domain", host=self.host ) # add in collision domains for this host (don't have platform) #TODO: need to allocate cds to a platform host_nodes += cd_nodes subgraph = self.nidb.subgraph(host_nodes, self.host) #TODO: sort this numerically, not just by string lab_topology.machines = " ".join( alpha_sort( naming.network_hostname(phy_node) for phy_node in subgraph.nodes("is_l3device"))) G_ip = self.anm['ip'] lab_topology.config_items = [] for node in sorted(subgraph.nodes("is_l3device")): for edge in node.edges(): collision_domain = str(G_ip.edge(edge).dst.subnet).replace( "/", ".") numeric_id = edge.id.replace( "eth", "") # netkit lab.conf uses 1 instead of eth1 lab_topology.config_items.append( device=naming.network_hostname(node), key=numeric_id, value=collision_domain, ) lab_topology.tap_ips = [] for node in subgraph: if node.tap: lab_topology.tap_ips.append( #TODO: merge the following and previous into a single function device=naming.network_hostname(node), id=node.tap.id.replace("eth", ""), # strip ethx -> x ip=node.tap.ip, ) lab_topology.tap_ips.sort("ip") lab_topology.config_items.sort("device")
def lab_topology(self): #TODO: replace name/label and use attribute from subgraph lab_topology = self.nidb.topology[self.host] lab_topology.render_template = "templates/netkit_lab_conf.mako" lab_topology.render_dst_folder = "rendered/%s/%s" % (self.host, "netkit") lab_topology.render_dst_file = "lab.conf" lab_topology.description = "AutoNetkit Lab" lab_topology.author = "AutoNetkit" lab_topology.web = "www.autonetkit.org" host_nodes = list(self.nidb.nodes(host = self.host, platform = "netkit")) if not len(host_nodes): log.debug("No Netkit hosts for %s" % self.host) #TODO: make so can return here #return # also need collision domains for this host cd_nodes = self.nidb.nodes("collision_domain", host = self.host) # add in collision domains for this host (don't have platform) #TODO: need to allocate cds to a platform host_nodes += cd_nodes subgraph = self.nidb.subgraph(host_nodes, self.host) #TODO: sort this numerically, not just by string lab_topology.machines = " ".join(alpha_sort(naming.network_hostname(phy_node) for phy_node in subgraph.nodes("is_l3device"))) G_ip = self.anm['ip'] lab_topology.config_items = [] for node in sorted(subgraph.nodes("is_l3device")): for edge in node.edges(): collision_domain = str(G_ip.edge(edge).dst.subnet).replace("/", ".") numeric_id = edge.id.replace("eth", "") # netkit lab.conf uses 1 instead of eth1 lab_topology.config_items.append( device = naming.network_hostname(node), key = numeric_id, value = collision_domain, ) local = node.interfaces[-1] id = local['id'].replace('eth','') domain = str(local['subnet']).replace('/','.') lab_topology.config_items.append( device = naming.network_hostname(node), key = id, value = domain) lab_topology.tap_ips = [] for node in subgraph: if node.tap: lab_topology.tap_ips.append( #TODO: merge the following and previous into a single function device= naming.network_hostname(node), id= node.tap.id.replace("eth", ""), # strip ethx -> x ip= node.tap.ip, ) lab_topology.tap_ips.sort("ip") lab_topology.config_items.sort("device")
def lab_topology(self): # TODO: replace name/label and use attribute from subgraph lab_topology = self.nidb.topology[self.host] lab_topology.render_template = "templates/netkit_lab_conf.mako" lab_topology.render_dst_folder = "rendered/%s_netkit" % (self.host) lab_topology.render_dst_file = "lab.conf" lab_topology.description = "AutoNetkit Lab" lab_topology.author = "AutoNetkit" lab_topology.web = "www.autonetkit.org" host_nodes = list( self.nidb.nodes(platform="netkit")) if not len(host_nodes): log.debug("No Netkit hosts for %s" % self.host) # TODO: make so can return here # return # also need collision domains for this host cd_nodes = self.nidb.nodes("collision_domain") host_nodes += cd_nodes subgraph = self.nidb.subgraph(host_nodes, self.host) # TODO: sort this numerically, not just by string lab_topology.machines = " ".join(alpha_sort(naming.network_hostname(phy_node) for phy_node in subgraph.nodes("is_l3device"))) lab_topology.config_items = [] for node in sorted(subgraph.nodes("is_l3device")): for interface in node.physical_interfaces: collision_domain = str(interface.ipv4_subnet).replace("/", ".") numeric_id = interface.numeric_id #netkit lab.conf uses 1 instead of eth1 lab_topology.config_items.append( device=naming.network_hostname(node), key=numeric_id, value=collision_domain, ) lab_topology.tap_ips = [] for node in subgraph: if node.tap: lab_topology.tap_ips.append( # TODO: merge the following and previous into a single # function device=naming.network_hostname(node), id=node.tap.id.replace("eth", ""), # strip ethx -> x ip=node.tap.ip, ) if node.memory: lab_topology.tap_ips[-1]["memory"] = node.memory lab_topology.tap_ips.sort("ip") lab_topology.config_items.sort("device")
def lab_topology(self): # TODO: replace name/label and use attribute from subgraph lab_topology = self.nidb.topology(self.host) lab_topology.render_template = os.path.join("templates", "netkit_lab_conf.mako") lab_topology.render_dst_folder = os.path.join("rendered", self.host, "netkit") lab_topology.render_dst_file = "lab.conf" lab_topology.description = "AutoNetkit Lab" lab_topology.author = "AutoNetkit" lab_topology.web = "www.autonetkit.org" host_nodes = list(self.nidb.nodes(host=self.host, platform="netkit")) if not len(host_nodes): log.debug("No Netkit hosts for %s" % self.host) # also need collision domains for this host cd_nodes = self.nidb.nodes("broadcast_domain", host=self.host) host_nodes += cd_nodes subgraph = self.nidb.subgraph(host_nodes, self.host) lab_topology.machines = " ".join( alpha_sort( naming.network_hostname(phy_node) for phy_node in subgraph.l3devices())) lab_topology.config_items = [] for node in sorted(subgraph.l3devices()): for interface in node.physical_interfaces(): broadcast_domain = str(interface.ipv4_subnet).replace("/", ".") #netkit lab.conf uses 1 instead of eth1 numeric_id = interface.numeric_id stanza = ConfigStanza( device=naming.network_hostname(node), key=numeric_id, value=broadcast_domain, ) lab_topology.config_items.append(stanza) lab_topology.tap_ips = [] for node in subgraph: if node.tap: stanza = ConfigStanza( device=naming.network_hostname(node), id=node.tap.id.replace("eth", ""), # strip ethx -> x ip=node.tap.ip, ) lab_topology.tap_ips.append(stanza) lab_topology.tap_ips = sorted(lab_topology.tap_ips, key=lambda x: x.ip) lab_topology.config_items = sorted(lab_topology.config_items, key=lambda x: x.device)
def lab_topology(self): # TODO: replace name/label and use attribute from subgraph lab_topology = self.nidb.topology(self.host) lab_topology.render_template = os.path.join("templates", "netkit_lab_conf.mako") lab_topology.render_dst_folder = os.path.join("rendered", self.host, "netkit") lab_topology.render_dst_file = "lab.conf" lab_topology.description = "AutoNetkit Lab" lab_topology.author = "AutoNetkit" lab_topology.web = "www.autonetkit.org" host_nodes = list( self.nidb.nodes(host=self.host, platform="netkit")) if not len(host_nodes): log.debug("No Netkit hosts for %s" % self.host) # also need collision domains for this host cd_nodes = self.nidb.nodes("broadcast_domain", host=self.host) host_nodes += cd_nodes subgraph = self.nidb.subgraph(host_nodes, self.host) lab_topology.machines = " ".join(alpha_sort(naming.network_hostname(phy_node) for phy_node in subgraph.l3devices())) lab_topology.config_items = [] for node in sorted(subgraph.l3devices()): for interface in node.physical_interfaces: broadcast_domain = str(interface.ipv4_subnet).replace("/", ".") #netkit lab.conf uses 1 instead of eth1 numeric_id = interface.numeric_id stanza = ConfigStanza( device=naming.network_hostname(node), key=numeric_id, value=broadcast_domain, ) lab_topology.config_items.append(stanza) lab_topology.tap_ips = [] for node in subgraph: if node.tap: stanza = ConfigStanza( device=naming.network_hostname(node), id=node.tap.id.replace("eth", ""), # strip ethx -> x ip=node.tap.ip, ) lab_topology.tap_ips.append(stanza) lab_topology.tap_ips = sorted(lab_topology.tap_ips, key = lambda x: x.ip) lab_topology.config_items = sorted(lab_topology.config_items, key = lambda x: x.device)
def compile(self, node): phy_node = self.anm['phy'].node(node) ipv4_node = self.anm['ipv4'].node(node) node.ip.use_ipv4 = phy_node.use_ipv4 or False node.ip.use_ipv6 = phy_node.use_ipv6 or False if not (node.ip.use_ipv4 and node.ip.use_ipv6): log.debug("Neither IPv4 nor IPv6 specified for %s, using IPv4" % node) #node.ip.use_ipv4 = True node.label = naming.network_hostname(phy_node) node.input_label = phy_node.id if node.ip.use_ipv4: node.loopback = ipv4_node.loopback node.loopback_subnet = netaddr.IPNetwork(node.loopback) node.loopback_subnet.prefixlen = 32 if self.anm['phy'].data.enable_routing: node.router_id = ipv4_node.loopback # applies even if ipv4 disabled, used for eg eigrp, bgp, ... self.interfaces(node) if self.anm.has_overlay("ospf") and node in self.anm['ospf']: self.ospf(node) if self.anm.has_overlay("isis") and node in self.anm['isis']: self.isis(node) if self.anm.has_overlay("eigrp") and node in self.anm['eigrp']: self.eigrp(node) if self.anm.has_overlay("bgp") and node in self.anm['bgp']: self.bgp(node)
def compile(self): log.info("Compiling Netkit for %s" % self.host) g_phy = self.anm['phy'] quagga_compiler = QuaggaCompiler(self.nidb, self.anm) # TODO: this should be all l3 devices not just routers for phy_node in g_phy.l3devices(host=self.host, syntax='quagga'): folder_name = naming.network_hostname(phy_node) DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") #TODO: order by folder and file template src/dst DmNode.render.base = os.path.join("templates","quagga") DmNode.render.template = os.path.join("templates", "netkit_startup.mako") DmNode.render.dst_folder = os.path.join("rendered", self.host, "netkit") DmNode.render.base_dst_folder = os.path.join("rendered", self.host, "netkit", folder_name) DmNode.render.dst_file = "%s.startup" % folder_name DmNode.render.custom = { 'abc': 'def.txt' } # allocate zebra information DmNode.add_stanza("zebra") if DmNode.is_router(): DmNode.zebra.password = "******" hostname = folder_name if hostname[0] in string.digits: hostname = "r" + hostname DmNode.hostname = hostname # can't have . in quagga hostnames DmNode.add_stanza("ssh") DmNode.ssh.use_key = True # TODO: make this set based on presence of key # Note this could take external data int_ids = itertools.count(0) for interface in DmNode.physical_interfaces: numeric_id = int_ids.next() interface.numeric_id = numeric_id interface.id = self.index_to_int_id(numeric_id) # and allocate tap interface DmNode.add_stanza("tap") DmNode.tap.id = self.index_to_int_id(int_ids.next()) quagga_compiler.compile(DmNode) if DmNode.bgp: DmNode.bgp.debug = True static_routes = [] DmNode.zebra.static_routes = static_routes # and lab.conf self.allocate_tap_ips() self.lab_topology()
def compile(self): log.info("Compiling Netkit for %s" % self.host) g_phy = self.anm['phy'] quagga_compiler = QuaggaCompiler(self.nidb, self.anm) # TODO: this should be all l3 devices not just routers for phy_node in g_phy.l3devices(host=self.host, syntax='quagga'): folder_name = naming.network_hostname(phy_node) nidb_node = self.nidb.node(phy_node) nidb_node.add_stanza("render") #TODO: order by folder and file template src/dst nidb_node.render.base = os.path.join("templates","quagga") nidb_node.render.template = os.path.join("templates", "netkit_startup.mako") nidb_node.render.dst_folder = os.path.join("rendered", self.host, "netkit") nidb_node.render.base_dst_folder = os.path.join("rendered", self.host, "netkit", folder_name) nidb_node.render.dst_file = "%s.startup" % folder_name nidb_node.render.custom = { 'abc': 'def.txt' } # allocate zebra information nidb_node.add_stanza("zebra") if nidb_node.is_router(): nidb_node.zebra.password = "******" hostname = folder_name if hostname[0] in string.digits: hostname = "r" + hostname nidb_node.hostname = hostname # can't have . in quagga hostnames nidb_node.add_stanza("ssh") nidb_node.ssh.use_key = True # TODO: make this set based on presence of key # Note this could take external data int_ids = itertools.count(0) for interface in nidb_node.physical_interfaces: numeric_id = int_ids.next() interface.numeric_id = numeric_id interface.id = self.index_to_int_id(numeric_id) # and allocate tap interface nidb_node.add_stanza("tap") nidb_node.tap.id = self.index_to_int_id(int_ids.next()) quagga_compiler.compile(nidb_node) if nidb_node.bgp: nidb_node.bgp.debug = True static_routes = [] nidb_node.zebra.static_routes = static_routes # and lab.conf self.allocate_tap_ips() self.lab_topology()
def compile(self, node): node.do_render = True # turn on rendering phy_node = self.anm['phy'].node(node) ipv4_node = self.anm['ipv4'].node(node) node.global_custom_config = phy_node.custom_config node.add_stanza("ip") node.ip.use_ipv4 = phy_node.use_ipv4 or False node.ip.use_ipv6 = phy_node.use_ipv6 or False if not (node.ip.use_ipv4 and node.ip.use_ipv6): node.log.debug( 'Neither IPv4 nor IPv6 specified: using default IPv4') self.static_routes(node) # node.ip.use_ipv4 = True node.label = naming.network_hostname(phy_node) node.input_label = phy_node.id if node.ip.use_ipv4: node.loopback = ipv4_node.loopback node.loopback_subnet = netaddr.IPNetwork(node.loopback) node.loopback_subnet.prefixlen = 32 if self.anm['phy'].data.enable_routing: # applies even if ipv4 disabled, used for eg eigrp, bgp, ... node.router_id = ipv4_node.loopback self.interfaces(node) if self.anm.has_overlay('ospf') and node in self.anm['ospf']: self.ospf(node) if self.anm.has_overlay('isis') and node in self.anm['isis']: self.isis(node) if self.anm.has_overlay('eigrp') and node in self.anm['eigrp']: self.eigrp(node) ###self.rip(node) if self.anm.has_overlay('rip') and node in self.anm['rip']: self.rip(node) # TODO: drop bgp overlay bgp_overlays = ["bgp", "ebgp_v4", "ibgp_v4", "ebgp_v6", "ibgp_v6"] use_bgp = False for overlay in bgp_overlays: if (self.anm.has_overlay(overlay) and node in self.anm[overlay] and self.anm[overlay].node(node).degree() > 0 ): use_bgp = True break if use_bgp: self.bgp(node)
def compile(self): log.info("Compiling Netkit for %s" % self.host) G_phy = self.anm.overlay.phy G_bgp = self.anm["bgp"] G_ip = self.anm["ip"] quagga_compiler = QuaggaCompiler(self.nidb, self.anm) # TODO: this should be all l3 devices not just routers for phy_node in G_phy.nodes("is_router", host=self.host, syntax="quagga"): folder_name = naming.network_hostname(phy_node) nidb_node = self.nidb.node(phy_node) nidb_node.render.base = "templates/quagga" nidb_node.render.template = "templates/netkit_startup.mako" nidb_node.render.dst_folder = "rendered/%s/%s" % (self.host, "nklab") nidb_node.render.base_dst_folder = "rendered/%s/%s/%s" % (self.host, "nklab", folder_name) nidb_node.render.dst_file = "%s.startup" % folder_name # allocate zebra information nidb_node.zebra.password = "******" nidb_node.zebra.hostname = folder_name # can't have . in quagga hostnames nidb_node.ssh.use_key = True # TODO: make this set based on presence of key # Note this could take external data int_ids = self.interface_ids() for edge in self.nidb.edges(nidb_node): edge.id = int_ids.next() # and allocate tap interface nidb_node.tap.id = int_ids.next() quagga_compiler.compile(nidb_node) # TODO: move these into inherited BGP config nidb_node.bgp.debug = True static_routes = [] """ for session in G_bgp.edges(phy_node): if session.type == "ebgp": neigh = session.dst nidb_neigh = self.nidb.node(neigh) ip_link = G_ip.edge(session) dst_int_ip = G_ip.edges(ip_link.dst, neigh).next().ip_address #TODO: split this to a helper function static_routes.append( { "description": neigh, "loopback": nidb_neigh.loopback_subnet, "next_hop": dst_int_ip, }) """ nidb_node.zebra.static_routes = static_routes # and lab.conf self.allocate_tap_ips() self.lab_topology()
def compile(self, node): node.do_render = True # turn on rendering phy_node = self.anm['phy'].node(node) ipv4_node = self.anm['ipv4'].node(node) node.global_custom_config = phy_node.custom_config node.add_stanza("ip") node.ip.use_ipv4 = phy_node.use_ipv4 or False node.ip.use_ipv6 = phy_node.use_ipv6 or False if not (node.ip.use_ipv4 and node.ip.use_ipv6): node.log.debug( 'Neither IPv4 nor IPv6 specified: using default IPv4') self.static_routes(node) # node.ip.use_ipv4 = True node.label = naming.network_hostname(phy_node) node.input_label = phy_node.id if node.ip.use_ipv4: node.loopback = ipv4_node.loopback node.loopback_subnet = netaddr.IPNetwork(node.loopback) node.loopback_subnet.prefixlen = 32 if self.anm['phy'].data.enable_routing: # applies even if ipv4 disabled, used for eg eigrp, bgp, ... node.router_id = ipv4_node.loopback self.interfaces(node) if self.anm.has_overlay('ospf') and node in self.anm['ospf']: self.ospf(node) if self.anm.has_overlay('isis') and node in self.anm['isis']: self.isis(node) if self.anm.has_overlay('eigrp') and node in self.anm['eigrp']: self.eigrp(node) ###self.rip(node) if self.anm.has_overlay('rip') and node in self.anm['rip']: self.rip(node) # TODO: drop bgp overlay bgp_overlays = ["bgp", "ebgp_v4", "ibgp_v4", "ebgp_v6", "ibgp_v6"] use_bgp = False for overlay in bgp_overlays: if (self.anm.has_overlay(overlay) and node in self.anm[overlay] and self.anm[overlay].node(node).degree() > 0): use_bgp = True break if use_bgp: self.bgp(node)
def compile(self, node): phy_node = self.anm['phy'].node(node) ip_node = self.anm['ip'].node(node) node.label = naming.network_hostname(phy_node) node.input_label = phy_node.id node.loopback = ip_node.loopback node.loopback_subnet = netaddr.IPNetwork(node.loopback) node.loopback_subnet.prefixlen = 32 self.interfaces(node) if node in self.anm['ospf']: self.ospf(node) if node in self.anm['ibgp'] or node in self.anm['ebgp']: self.bgp(node)
def compile(self, node): phy_node = self.anm['phy'].node(node) ip_node = self.anm.overlay.ip.node(node) node.label = naming.network_hostname(phy_node) node.input_label = phy_node.id node.loopback = ip_node.loopback node.loopback_subnet = netaddr.IPNetwork(node.loopback) node.loopback_subnet.prefixlen = 32 self.interfaces(node) if node in self.anm['ospf']: self.ospf(node) if node in self.anm['bgp']: self.bgp(node)
def compile(self): log.info("Compiling Cisco for %s" % self.host) G_phy = self.anm.overlay.phy ios_compiler = IosCompiler(self.nidb, self.anm) for phy_node in G_phy.nodes("is_router", host=self.host, syntax="ios"): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = "templates/ios.mako" nidb_node.render.dst_folder = os.path.join(self.host, self.timestamp) nidb_node.render.dst_file = "%s.conf" % naming.network_hostname(phy_node) # Assign interfaces int_ids = self.interface_ids_ios() for edge in self.nidb.edges(nidb_node): edge.id = int_ids.next() ios_compiler.compile(nidb_node)
def compile(self): log.info("Compiling Netkit for %s" % self.host) g_phy = self.anm['phy'] quagga_compiler = QuaggaCompiler(self.nidb, self.anm) # TODO: this should be all l3 devices not just routers for phy_node in g_phy.nodes('is_router', host=self.host, syntax='quagga'): folder_name = naming.network_hostname(phy_node) nidb_node = self.nidb.node(phy_node) nidb_node.render.base = "templates/quagga" nidb_node.render.template = "templates/netkit_startup.mako" nidb_node.render.dst_folder = "rendered/%s/%s" % ( self.host, "netkit") nidb_node.render.base_dst_folder = "rendered/%s/%s/%s" % ( self.host, "netkit", folder_name) nidb_node.render.dst_file = "%s.startup" % folder_name # allocate zebra information nidb_node.zebra.password = "******" hostname = folder_name if hostname[0] in string.digits: hostname = "r" + hostname nidb_node.zebra.hostname = hostname # can't have . in quagga hostnames nidb_node.ssh.use_key = True # TODO: make this set based on presence of key # Note this could take external data int_ids = self.interface_ids() for edge in self.nidb.edges(nidb_node): edge.id = int_ids.next() # and allocate tap interface nidb_node.tap.id = int_ids.next() quagga_compiler.compile(nidb_node) # TODO: move these into inherited BGP config nidb_node.bgp.debug = True static_routes = [] nidb_node.zebra.static_routes = static_routes # ------------construction du dns pour le nidb for phy_node in g_phy.nodes('is_router', host=self.host, syntax='quagga'): nidb_node = self.nidb.node(phy_node) if nidb_node in self.anm['dns']: # seuls les noeud CL, NS, RS, DNSR et WS sont concernes self.dns(nidb_node) # and lab.conf self.allocate_tap_ips() self.lab_topology()
def compile(self): log.info("Compiling Netkit for %s" % self.host) g_phy = self.anm['phy'] quagga_compiler = QuaggaCompiler(self.nidb, self.anm) # TODO: this should be all l3 devices not just routers for phy_node in g_phy.nodes('is_router', host=self.host, syntax='quagga'): folder_name = naming.network_hostname(phy_node) nidb_node = self.nidb.node(phy_node) nidb_node.render.base = "templates/quagga" nidb_node.render.template = "templates/netkit_startup.mako" nidb_node.render.dst_folder = "rendered/%s/%s" % ( self.host, "netkit") nidb_node.render.base_dst_folder = "rendered/%s/%s/%s" % ( self.host, "netkit", folder_name) nidb_node.render.dst_file = "%s.startup" % folder_name # allocate zebra information nidb_node.zebra.password = "******" hostname = folder_name if hostname[0] in string.digits: hostname = "r" + hostname nidb_node.zebra.hostname = hostname # can't have . in quagga hostnames nidb_node.ssh.use_key = True # TODO: make this set based on presence of key # Note this could take external data int_ids = itertools.count(0) for interface in nidb_node.physical_interfaces: numeric_id = int_ids.next() interface.numeric_id = numeric_id interface.id = self.index_to_int_id(numeric_id) # and allocate tap interface nidb_node.tap.id = self.index_to_int_id(int_ids.next()) quagga_compiler.compile(nidb_node) # TODO: move these into inherited BGP config nidb_node.bgp.debug = True static_routes = [] nidb_node.zebra.static_routes = static_routes # and lab.conf self.allocate_tap_ips() self.lab_topology()
def compile(self): log.info("Compiling Netkit for %s" % self.host) G_phy = self.anm['phy'] quagga_compiler = QuaggaCompiler(self.nidb, self.anm) #TODO: this should be all l3 devices not just routers for phy_node in G_phy.nodes('is_router', host=self.host, syntax='quagga'): folder_name = naming.network_hostname(phy_node) nidb_node = self.nidb.node(phy_node) nidb_node.render.base = "templates/quagga" nidb_node.render.template = "templates/netkit_startup.mako" nidb_node.render.dst_folder = "rendered/%s/%s" % (self.host, "netkit") nidb_node.render.base_dst_folder = "rendered/%s/%s/%s" % ( self.host, "netkit", folder_name) nidb_node.render.dst_file = "%s.startup" % folder_name # allocate zebra information nidb_node.zebra.password = "******" hostname = folder_name if hostname[0] in string.digits: hostname = "r" + hostname nidb_node.zebra.hostname = hostname # can't have . in quagga hostnames nidb_node.ssh.use_key = True #TODO: make this set based on presence of key # Note this could take external data int_ids = self.interface_ids() for edge in self.nidb.edges(nidb_node): edge.id = int_ids.next() # and allocate tap interface nidb_node.tap.id = int_ids.next() quagga_compiler.compile(nidb_node) #TODO: move these into inherited BGP config nidb_node.bgp.debug = True static_routes = [] nidb_node.zebra.static_routes = static_routes # and lab.conf self.allocate_tap_ips() self.lab_topology()
def compile(self, node): phy_node = self.anm['phy'].node(node) ipv4_node = self.anm['ipv4'].node(node) node.ip.use_ipv4 = phy_node.use_ipv4 node.ip.use_ipv6 = phy_node.use_ipv6 if not (node.ip.use_ipv4 and node.ip.use_ipv6): log.debug("Neither IPv4 nor IPv6 specified for %s, using IPv4" % node) node.ip.use_ipv4 = True node.label = naming.network_hostname(phy_node) node.input_label = phy_node.id node.loopback = ipv4_node.loopback node.loopback_subnet = netaddr.IPNetwork(node.loopback) node.loopback_subnet.prefixlen = 32 self.interfaces(node) if node in self.anm['ospf']: self.ospf(node) if node in self.anm['bgp']: self.bgp(node)
def compile(self, node): phy_node = self.anm['phy'].node(node) ipv4_node = self.anm['ipv4'].node(node) node.ip.use_ipv4 = phy_node.use_ipv4 or False node.ip.use_ipv6 = phy_node.use_ipv6 or False if not (node.ip.use_ipv4 and node.ip.use_ipv6): log.debug("Neither IPv4 nor IPv6 specified for %s, using IPv4" % node) node.ip.use_ipv4 = True node.label = naming.network_hostname(phy_node) node.input_label = phy_node.id node.loopback = ipv4_node.loopback node.loopback_subnet = netaddr.IPNetwork(node.loopback) node.loopback_subnet.prefixlen = 32 self.interfaces(node) if node in self.anm['ospf']: self.ospf(node) if node in self.anm['isis']: self.isis(node) if node in self.anm['bgp']: self.bgp(node)
def compile(self): self.copy_across_ip_addresses() log.info("Compiling Netkit for %s" % self.host) g_phy = self.anm['phy'] quagga_compiler = QuaggaCompiler(self.nidb, self.anm) # todo: set platform render lab_topology = self.nidb.topology(self.host) lab_topology.render2 = PlatformRender() # TODO: this should be all l3 devices not just routers for phy_node in g_phy.l3devices(host=self.host, syntax='quagga'): folder_name = naming.network_hostname(phy_node) dm_node = self.nidb.node(phy_node) dm_node.add_stanza("render") # TODO: order by folder and file template src/dst dm_node.render.base = os.path.join("templates", "quagga") dm_node.render.template = os.path.join("templates", "netkit_startup.mako") dm_node.render.dst_folder = os.path.join("rendered", self.host, "netkit") dm_node.render.base_dst_folder = os.path.join( "rendered", self.host, "netkit", folder_name) dm_node.render.dst_file = "%s.startup" % folder_name dm_node.render.custom = {'abc': 'def.txt'} render2 = NodeRender() # TODO: dest folder also needs to be able to accept a list # TODO: document that use a list so can do native os.path.join on # target platform render2.add_folder(["templates", "quagga"], folder_name) render2.add_file(("templates", "netkit_startup.mako"), "%s.startup" % folder_name) dm_node.render2 = render2 lab_topology.render2.add_node(dm_node) # lab_topology.render2_hosts.append(phy_node) # allocate zebra information dm_node.add_stanza("zebra") if dm_node.is_router(): dm_node.zebra.password = "******" hostname = folder_name if hostname[0] in string.digits: hostname = "r" + hostname dm_node.hostname = hostname # can't have . in quagga hostnames dm_node.add_stanza("ssh") # TODO: make this set based on presence of key dm_node.ssh.use_key = True # Note this could take external data int_ids = itertools.count(0) for interface in dm_node.physical_interfaces(): numeric_id = int_ids.next() interface.numeric_id = numeric_id interface.id = self.index_to_int_id(numeric_id) # and allocate tap interface dm_node.add_stanza("tap") dm_node.tap.id = self.index_to_int_id(int_ids.next()) quagga_compiler.compile(dm_node) if dm_node.bgp: dm_node.bgp.debug = True static_routes = [] dm_node.zebra.static_routes = static_routes # and lab.conf self.allocate_tap_ips() self.allocate_lab_topology()
def compile(self): log.info("Compiling Netkit(STRIP) for %s" % self.host) G_phy = self.anm.overlay.phy IP = self.anm.overlay.ip Input = self.anm._overlays['input'] quagga_compiler = STRIPCompiler(self.nidb, self.anm) #TODO: this should be all l3 devices not just routers for phy_node in G_phy.nodes('is_router', host = self.host, syntax='quagga'): folder_name = naming.network_hostname(phy_node) nidb_node = self.nidb.node(phy_node) nidb_node.render.base = "templates/STRIP" nidb_node.render.template = "templates/netkit_startup_STRIP.mako" nidb_node.render.dst_folder = "rendered/%s/%s" % (self.host, "netkit") nidb_node.render.base_dst_folder = "rendered/%s/%s/%s" % (self.host, "netkit", folder_name) nidb_node.render.dst_file = "%s.startup" % folder_name # allocate STRIP information neighbours = G_phy.neighbors(phy_node) edges = G_phy.edges(src_nbunch=phy_node, dst_nbunch=neighbours) neighbours = G_phy._graph[phy_node.id] nbrips = [] nbrnames = [] nbrdists = [] for neighbour in neighbours: cd = None try: cd = IP._graph.edge['cd_%s_%s' % (phy_node.id, neighbour)] except: cd = IP._graph.edge['cd_%s_%s' % (neighbour, phy_node.id)] ipaddr = cd[neighbour]['ip_address'] nbrnames.append(neighbour) nbrips.append('%s:1234' % str(ipaddr)) nbrdists.append(str(Input[phy_node.id][neighbour]['weight'])) nidb_node.strip.nbrIPs = ','.join(nbrips) nidb_node.strip.nbrNames = ','.join(nbrnames) nidb_node.strip.nbrDists = ','.join(nbrdists) #nidb_node.strip.net = '10.0.%d.0' % phy_node.asn #nidb_node.strip.netbroadcast = '10.0.%d.255' % phy_node.asn #nidb_node.strip.netmask = '255.255.255.0' #nidb_node.strip.netdev = 'eth%d' % phy_node._next_int_id # allocate zebra information nidb_node.zebra.password = "******" hostname = folder_name if hostname[0] in string.digits: hostname = "r" + hostname nidb_node.zebra.hostname = hostname # can't have . in quagga hostnames nidb_node.ssh.use_key = True #TODO: make this set based on presence of key # Note this could take external data int_ids = self.interface_ids() for edge in self.nidb.edges(nidb_node): edge.id = int_ids.next() # and allocate tap interface nidb_node.tap.id = int_ids.next() quagga_compiler.compile(nidb_node) #TODO: move these into inherited BGP config nidb_node.bgp.debug = True static_routes = [] nidb_node.zebra.static_routes = static_routes # and lab.conf self.allocate_tap_ips() self.lab_topology()
def compile_devices(self): import re g_phy = self.anm['phy'] to_memory, use_mgmt_interfaces, dst_folder = self._parameters() if use_mgmt_interfaces: log.debug("Allocating VIRL management interfaces") else: log.debug("Not allocating VIRL management interfaces") if g_phy.data.mgmt_block is not None: mgmt_address_block = netaddr.IPNetwork(g_phy.data.mgmt_block).iter_hosts() if g_phy.data.vpcid_block is not None: vpc_re = "([0-9]+)(-)([0-9]+)" #vpc_id_start = int(re.search(vpc_re, g_phy.data.vpcid_block).group(1)) #vpc_id_end = int(re.search(vpc_re, g_phy.data.vpcid_block).group(3)) #vpc_id_range = vpc_id_end-vpc_id_start vpc_id_start = 1 vpc_id_end = 1000 vpc_id_range = 999 # TODO: need to copy across the interface name from edge to the interface # TODO: merge common router code, so end up with three loops: routers, ios # routers, ios_xr routers # TODO: Split out each device compiler into own function # TODO: look for unused code paths here - especially for interface # allocation # store autonetkit_cisco version log.debug("Generating device configurations") from pkg_resources import get_distribution # Copy across indices for external connectors (e.g may want to copy # configs) external_connectors = [n for n in g_phy if n.host == self.host and n.device_type == "external_connector"] for phy_node in external_connectors: DmNode = self.nidb.node(phy_node) DmNode.indices = phy_node.indices g_input = self.anm['input'] node_profiles = g_input.data['profiles'] managed_switches = [n for n in g_phy.switches() if n.host == self.host and n.device_subtype == "managed"] for phy_node in managed_switches: DmNode = self.nidb.node(phy_node) DmNode.indices = phy_node.indices numeric_vpc_ids = self.numeric_vpc_ids(vpc_id_start,vpc_id_end) for phy_node in g_phy.l3devices(host=self.host): loopback_ids = self.loopback_interface_ids() # allocate loopbacks to routes (same for all ios variants) DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.indices = phy_node.indices #NTP configuration DmNode.add_stanza("syslog") if g_phy.data.mgmt_block is not None: DmNode.add_stanza('mgmt') DmNode.mgmt.ip = mgmt_address_block.next() # for node_data in phy_node._graph.node: for node_id in node_profiles: #if DmNode._graph.node[node_data]['profile'] == node_id['id']: if not phy_node._graph.node[phy_node.id]['profile'] is None: if phy_node._graph.node[phy_node.id]['profile'] == node_id['id']: if node_id.has_key('configs'): if node_id['configs'].has_key('ntp'): DmNode.add_stanza("ntp") DmNode.ntp.enabled = node_id['configs']['ntp'].get('enabled') DmNode.ntp.server_ip = node_id['configs']['ntp'].get('server_ip') if node_id['configs'].has_key('snmp'): DmNode.add_stanza('snmp') DmNode.snmp.enabled = node_id['configs']['snmp'].get('enabled') DmNode.snmp.server=[] for server in node_id['configs']['snmp']['servers']: snmp_server_stanza = ConfigStanza(ip = server['ip'], version = server['version'], udp_port=server['udp_port'], community=server['community']) DmNode.snmp.server.append(snmp_server_stanza) DmNode.snmp.users = [] for user_prof in node_id['configs']['snmp']['users']: snmp_user_stanza = ConfigStanza(user=user_prof['user'], auth=user_prof['auth'], pwd=user_prof['pwd'], priv_passphrase=user_prof['priv_passphrase'], engine_id=user_prof['engineID']) DmNode.snmp.users.append(snmp_user_stanza) DmNode.snmp.features=[] for configs in node_id['configs']['snmp']['features']: snmp_feature_stanza = ConfigStanza(id=configs['id'], enabled=configs['enabled']) DmNode.snmp.features.append(snmp_feature_stanza) break """for node_id in node_profiles: if DmNode._graph.node['profile'] == node_id['id']: DmNode.ntp.enabled = node_profiles[0]['configs']['ntp'].get('enabled') DmNode.ntp.server_ip = node_profiles[0]['configs']['ntp'].get('server_ip') """ #End ntp config #syslog config for node_id in node_profiles: #if DmNode._graph.node[node_data]['profile'] == node_id['id']: if not phy_node._graph.node[phy_node.id]['syslog'] is None: if phy_node._graph.node[phy_node.id]['syslog'] == node_id['id']: DmNode.syslog.enabled = node_id['configs']['syslog'].get('enabled') DmNode.syslog.server_ip = node_id['configs']['syslog'].get('severity') break #end syslog config for interface in DmNode.loopback_interfaces(): if interface != DmNode.loopback_zero: interface.id = loopback_ids.next() # numeric ids numeric_int_ids = self.numeric_interface_ids() for interface in DmNode.physical_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id # numeric ids numeric_po_ids = self.numeric_portchannel_ids() for interface in DmNode.portchannel_interfaces(): po_interface = phy_node.interface(interface) interface.numeric_id = int(po_interface.id[po_interface.id.rfind('_')+1:]) po_specified_id = phy_node.interface(interface).specified_id if po_specified_id is not None: interface.id = po_specified_id for po_mem_int in DmNode.physical_interfaces(): po_mem_interface = phy_node.interface(po_mem_int) if po_mem_interface.id in po_interface.members: po_mem_int.channel_group = interface.numeric_id po_interface_int = po_interface._interface if po_interface_int.has_key('subcat_prot'): if po_interface.subcat_prot == "vpc": po_mem_int.member_port_vpc = 1 interface.virt_port_channel = 1 DmNode.add_stanza('vpc') DmNode.vpc.domain_id = (po_mem_int.channel_group)%vpc_id_range dest = po_interface_int['interfaces'][0]['description'] DmNode.vpc.dest = dest[3:] elif po_interface.subcat_prot == "vpc-member": interface.vpc_member_id = (po_mem_int.channel_group)%1000 #adding destination ip for vpc over here for phy_node in g_phy.l3devices(host=self.host): DmNode = self.nidb.node(phy_node) if DmNode.vpc: dest_id = DmNode.vpc.dest for phy_node_1 in g_phy.l3devices(host=self.host): if phy_node_1.id == dest_id: DmNode_1 = self.nidb.node(phy_node_1) DmNode.vpc.dest = DmNode_1.mgmt.ip break #from autonetkit.compilers.device.ubuntu import UbuntuCompiler #from autonetkit_cisco.compilers.device.ubuntu import UbuntuCompiler #ubuntu_compiler = UbuntuCompiler(self.nidb, self.anm) for phy_node in g_phy.servers(host=self.host): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.add_stanza("ip") #interface.id = self.numeric_to_interface_label_linux(interface.numeric_id) # print "numeric", interface.numeric_id, interface.id DmNode.ip.use_ipv4 = phy_node.use_ipv4 DmNode.ip.use_ipv6 = phy_node.use_ipv6 # TODO: clean up interface handling numeric_int_ids = self.numeric_interface_ids() for interface in DmNode.physical_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id # numeric ids numeric_po_ids = self.numeric_portchannel_ids() for interface in DmNode.portchannel_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_po_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id # TODO: make this part of the base device compiler, which # server/router inherits # not these are physical interfaces; configure after previous # config steps if use_mgmt_interfaces: mgmt_int = DmNode.add_interface( management=True, description="eth0") mgmt_int_id = "eth0" mgmt_int.id = mgmt_int_id # render route config DmNode = self.nidb.node(phy_node) #ubuntu_compiler.compile(DmNode) if not phy_node.dont_configure_static_routing: DmNode.render.template = os.path.join( "templates", "linux", "static_route.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # TODO: refactor out common logic ios_compiler = IosClassicCompiler(self.nidb, self.anm) host_routers = g_phy.routers(host=self.host) ios_nodes = (n for n in host_routers if n.syntax in ("ios", "ios_xe")) for phy_node in ios_nodes: if phy_node.devsubtype == "core": continue DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "ios.mako") to_memory = False if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # TODO: write function that assigns interface number excluding # those already taken # Assign interfaces if phy_node.device_subtype == "IOSv": int_ids = self.interface_ids_ios() numeric_to_interface_label = self.numeric_to_interface_label_ios elif phy_node.device_subtype == "CSR1000v": int_ids = self.interface_ids_csr1000v() numeric_to_interface_label = self.numeric_to_interface_label_ra else: # default if no subtype specified # TODO: need to set default in the load module log.warning("Unexpected subtype %s for %s" % (phy_node.device_subtype, phy_node)) int_ids = self.interface_ids_ios() numeric_to_interface_label = self.numeric_to_interface_label_ios numeric_to_portchannel_interface_label = self.numeric_to_portchannel_interface_label_ios if use_mgmt_interfaces: if phy_node.device_subtype == "IOSv": # TODO: make these configured in the internal config file # for platform/device_subtype keying mgmt_int_id = "GigabitEthernet0/0" if phy_node.device_subtype == "CSR1000v": mgmt_int_id = "GigabitEthernet1" for interface in DmNode.physical_interfaces(): # TODO: use this code block once for all routers if not interface.id: interface.id = numeric_to_interface_label( interface.numeric_id) else: if interface.id[0] == 'e' or interface.id[0] == 'E': #import re port_re = "([a-zA-Z]+)([0-9]+/[0-9]+)" interface.id = "%s %s"%((re.search(port_re,interface.id)).group(1), (re.search(port_re,interface.id)).group(2)) for interface in DmNode.portchannel_interfaces(): # TODO: use this code block once for all routers #if not interface.id: interface.id = numeric_to_portchannel_interface_label( interface.numeric_id) ios_compiler.compile(DmNode) if use_mgmt_interfaces: mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id nxos_compiler = NxOsCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='nx_os'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "nx_os.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_nxos( interface.numeric_id) DmNode.supported_features = ConfigStanza( mpls_te=False, mpls_oam=False, vrf=False) nxos_compiler.compile(DmNode) # TODO: make this work other way around if use_mgmt_interfaces: mgmt_int_id = "mgmt0" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id staros_compiler = StarOsCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='StarOS'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "staros.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_star_os( interface.numeric_id) staros_compiler.compile(DmNode) # TODO: make this work other way around if use_mgmt_interfaces: mgmt_int_id = "ethernet 1/1" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id
def compile(self): G_in = self.anm['input'] G_in_directed = self.anm['input_directed'] specified_int_names = G_in.data.specified_int_names g_phy = self.anm['phy'] log.info("Compiling Cisco for %s" % self.host) ios_compiler = IosClassicCompiler(self.nidb, self.anm) now = datetime.now() if settings['Compiler']['Cisco']['timestamp']: timestamp = now.strftime("%Y%m%d_%H%M%S_%f") dst_folder = "rendered/%s_%s/%s" % ( self.host, timestamp, "cisco") # TODO: use os.path.join else: dst_folder = "rendered/%s/%s" % (self.host, "cisco") # TODO: merge common router code, so end up with three loops: routers, ios # routers, ios2 routers for phy_node in g_phy.nodes('is_router', host=self.host, syntax='ios'): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = "templates/ios.mako" if self.to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_ios() int_ids.next() # 0/0 is used for management ethernet for edge in sorted(self.nidb.edges(nidb_node), key=self.edge_id_numeric): if specified_int_names: directed_edge = G_in_directed.edge(edge) edge.id = directed_edge.name else: edge.id = int_ids.next() ios_compiler.compile(nidb_node) ios2_compiler = Ios2Compiler(self.nidb, self.anm) for phy_node in g_phy.nodes('is_router', host=self.host, syntax='ios2'): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = "templates/ios2/router.conf.mako" if self.to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_ios2() for edge in sorted(self.nidb.edges(nidb_node), key=self.edge_id_numeric): if specified_int_names: directed_edge = G_in_directed.edge(edge) edge.id = directed_edge.name else: edge.id = int_ids.next() ios2_compiler.compile(nidb_node) nxos_compiler = NxOsCompiler(self.nidb, self.anm) for phy_node in g_phy.nodes('is_router', host=self.host, syntax='nx_os'): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = "templates/nx_os.mako" if self.to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for edge in sorted(self.nidb.edges(nidb_node), key=self.edge_id_numeric): if specified_int_names: directed_edge = G_in_directed.edge(edge) edge.id = directed_edge.name else: edge.id = int_ids.next() nxos_compiler.compile(nidb_node) other_nodes = [phy_node for phy_node in g_phy.nodes('is_router', host=self.host) if phy_node.syntax not in ("ios", "ios2")] for node in other_nodes: phy_node = g_phy.node(node) nidb_node = self.nidb.node(phy_node) nidb_node.input_label = phy_node.id # set specifically for now for other variants
def compile(self): def edge_id_numeric(edge): """ Used for sorting assumes format xx_src_dst -> return the xx component""" try: return int(edge.edge_id.split("_")[0]) except ValueError: return edge.edge_id # not numeric G_in = self.anm['input'] G_in_directed = self.anm['input_directed'] specified_int_names = G_in.data.specified_int_names log.info("Compiling Cisco for %s" % self.host) G_phy = self.anm.overlay.phy ios_compiler = IosClassicCompiler(self.nidb, self.anm) now = datetime.now() if settings['Compiler']['Cisco']['timestamp']: timestamp = now.strftime("%Y%m%d_%H%M%S_%f") dst_folder = "rendered/%s_%s/%s" % (self.host, timestamp, "cisco") #TODO: use os.path.join else: dst_folder = "rendered/%s/%s" % (self.host,"cisco") #TODO: merge common router code, so end up with three loops: routers, ios routers, ios2 routers for phy_node in G_phy.nodes('is_router', host = self.host, syntax='ios'): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = "templates/ios.mako" if self.to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname(phy_node) # Assign interfaces int_ids = self.interface_ids_ios() int_ids.next() # 0/0 is used for management ethernet for edge in sorted(self.nidb.edges(nidb_node), key = edge_id_numeric): if specified_int_names: directed_edge = G_in_directed.edge(edge) edge.id = directed_edge.name else: edge.id = int_ids.next() ios_compiler.compile(nidb_node) ios2_compiler = Ios2Compiler(self.nidb, self.anm) for phy_node in G_phy.nodes('is_router', host = self.host, syntax='ios2'): nidb_node = self.nidb.node(phy_node) #nidb_node.render.base = "templates/ios2" #nidb_node.render.base_dst_folder = "rendered/%s/%s/%s" % (self.host, "cisco", folder_name) nidb_node.render.template = "templates/ios2/router.conf.mako" if self.to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname(phy_node) # Assign interfaces int_ids = self.interface_ids_ios2() for edge in sorted(self.nidb.edges(nidb_node), key = edge_id_numeric): if specified_int_names: directed_edge = G_in_directed.edge(edge) edge.id = directed_edge.name else: edge.id = int_ids.next() ios2_compiler.compile(nidb_node) other_nodes = [phy_node for phy_node in G_phy.nodes('is_router', host = self.host) if phy_node.syntax not in ("ios", "ios2")] for node in other_nodes: phy_node = G_phy.node(node) nidb_node = self.nidb.node(phy_node) nidb_node.input_label = phy_node.id # set specifically for now for other variants
def compile(self): G_in = self.anm['input'] specified_int_names = G_in.data.specified_int_names #TODO: need to copy across the interface name from edge to the interface g_phy = self.anm['phy'] log.info("Compiling Cisco for %s" % self.host) ios_compiler = IosClassicCompiler(self.nidb, self.anm) now = datetime.now() if settings['Compiler']['Cisco']['timestamp']: timestamp = now.strftime("%Y%m%d_%H%M%S_%f") dst_folder = "rendered/%s_%s/%s" % ( self.host, timestamp, "cisco") # TODO: use os.path.join else: dst_folder = "rendered/%s/%s" % (self.host, "cisco") # TODO: merge common router code, so end up with three loops: routers, ios # routers, ios2 routers for phy_node in g_phy.nodes('is_router', host=self.host): loopback_ids = self.loopback_interface_ids() # allocate loopbacks to routes (same for all ios variants) nidb_node = self.nidb.node(phy_node) for interface in nidb_node.loopback_interfaces: if interface != nidb_node.loopback_zero: interface.id = loopback_ids.next() for phy_node in g_phy.nodes('is_router', host=self.host, syntax='ios'): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = "templates/ios.mako" if self.to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_ios() int_ids.next() # 0/0 is used for management ethernet for interface in nidb_node.physical_interfaces: if specified_int_names: interface.id = phy_node.interface(interface).name # TODO: need to determine if interface name already specified else: interface.id = int_ids.next() ios_compiler.compile(nidb_node) ios2_compiler = Ios2Compiler(self.nidb, self.anm) for phy_node in g_phy.nodes('is_router', host=self.host, syntax='ios2'): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = "templates/ios2/router.conf.mako" if self.to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_ios2() for interface in nidb_node.physical_interfaces: if specified_int_names: interface.id = phy_node.interface(interface).name # TODO: need to determine if interface name already specified else: interface.id = int_ids.next() ios2_compiler.compile(nidb_node) nxos_compiler = NxOsCompiler(self.nidb, self.anm) for phy_node in g_phy.nodes('is_router', host=self.host, syntax='nx_os'): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = "templates/nx_os.mako" if self.to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in nidb_node.physical_interfaces: if specified_int_names: interface.id = phy_node.interface(interface).name # TODO: need to determine if interface name already specified else: interface.id = int_ids.next() nxos_compiler.compile(nidb_node) other_nodes = [phy_node for phy_node in g_phy.nodes('is_router', host=self.host) if phy_node.syntax not in ("ios", "ios2")] for node in other_nodes: phy_node = g_phy.node(node) nidb_node = self.nidb.node(phy_node) nidb_node.input_label = phy_node.id # set specifically for now for other variants
def compile(self): settings = autonetkit.config.settings to_memory = settings['Compiler']['Cisco']['to memory'] #TODO: need to copy across the interface name from edge to the interface g_phy = self.anm['phy'] use_mgmt_interfaces = g_phy.data.mgmt_interfaces_enabled if use_mgmt_interfaces: log.info("Allocating management interfaces for Cisco") else: log.info("Not allocating management interfaces for Cisco") log.info("Compiling Cisco for %s" % self.host) ios_compiler = IosClassicCompiler(self.nidb, self.anm) now = datetime.now() if settings['Compiler']['Cisco']['timestamp']: timestamp = now.strftime("%Y%m%d_%H%M%S_%f") dst_folder = os.path.join("rendered", self.host, timestamp, "cisco") else: dst_folder = os.path.join("rendered", self.host, "cisco") # TODO: merge common router code, so end up with three loops: routers, ios # routers, ios2 routers # store autonetkit_cisco version from pkg_resources import get_distribution ank_cisco_version = get_distribution("autonetkit_cisco").version for phy_node in g_phy.nodes('is_router', host=self.host): loopback_ids = self.loopback_interface_ids() # allocate loopbacks to routes (same for all ios variants) nidb_node = self.nidb.node(phy_node) nidb_node.ank_cisco_version = ank_cisco_version for interface in nidb_node.loopback_interfaces: if interface != nidb_node.loopback_zero: interface.id = loopback_ids.next() for phy_node in g_phy.nodes('is_router', host=self.host, syntax='ios'): specified_int_names = phy_node.specified_int_names nidb_node = self.nidb.node(phy_node) nidb_node.render.template = os.path.join("templates","ios.mako") if to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces if phy_node.device_subtype == "os": int_ids = self.interface_ids_ios() elif phy_node.device_subtype == "ra": int_ids = self.interface_ids_ra() else: # default if no subtype specified #TODO: need to set default in the load module log.warning("Unexpected subtype %s" % phy_node.device_subtype) int_ids = self.interface_ids_ios() if use_mgmt_interfaces: mgmt_int_id = int_ids.next() # 0/0 is used for management ethernet for interface in nidb_node.physical_interfaces: if specified_int_names: interface.id = phy_node.interface(interface).name # TODO: need to determine if interface name already specified else: interface.id = int_ids.next() ios_compiler.compile(nidb_node) if use_mgmt_interfaces: mgmt_int = nidb_node.add_interface(management = True) mgmt_int.id = mgmt_int_id ios2_compiler = Ios2Compiler(self.nidb, self.anm) for phy_node in g_phy.nodes('is_router', host=self.host, syntax='ios2'): specified_int_names = phy_node.specified_int_names nidb_node = self.nidb.node(phy_node) nidb_node.render.template = os.path.join("templates","ios2","router.conf.mako") if to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_ios2() for interface in nidb_node.physical_interfaces: if specified_int_names: interface.id = phy_node.interface(interface).name # TODO: need to determine if interface name already specified else: interface.id = int_ids.next() ios2_compiler.compile(nidb_node) if use_mgmt_interfaces: mgmt_int_id = "mgmteth0/0/CPU0/0" mgmt_int = nidb_node.add_interface(management = True) mgmt_int.id = mgmt_int_id nxos_compiler = NxOsCompiler(self.nidb, self.anm) for phy_node in g_phy.nodes('is_router', host=self.host, syntax='nx_os'): nidb_node = self.nidb.node(phy_node) nidb_node.render.template = os.path.join("templates","nx_os.mako") if to_memory: nidb_node.render.to_memory = True else: nidb_node.render.dst_folder = dst_folder nidb_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in nidb_node.physical_interfaces: if specified_int_names: interface.id = phy_node.interface(interface).name # TODO: need to determine if interface name already specified else: interface.id = int_ids.next() if use_mgmt_interfaces: mgmt_int_id = "mgmt0" mgmt_int = nidb_node.add_interface(management = True) mgmt_int.id = mgmt_int_id nxos_compiler.compile(nidb_node) other_nodes = [phy_node for phy_node in g_phy.nodes('is_router', host=self.host) if phy_node.syntax not in ("ios", "ios2")] for node in other_nodes: #TODO: check why we need this phy_node = g_phy.node(node) nidb_node = self.nidb.node(phy_node) nidb_node.input_label = phy_node.id # set specifically for now for other variants # TODO: use more os.path.join for render folders # TODO: Split compilers into seperate modules if use_mgmt_interfaces: self.assign_management_interfaces()
def compile_devices(self): import re g_phy = self.anm['phy'] to_memory, use_mgmt_interfaces, dst_folder = self._parameters() if use_mgmt_interfaces: log.debug("Allocating VIRL management interfaces") else: log.debug("Not allocating VIRL management interfaces") pc_only_config = False vxlan_global_config = None if g_phy.data.vxlan_global_config is not None: vxlan_global_config = g_phy.data.vxlan_global_config if g_phy.data.pc_only is not None: pc_only_config = g_phy.data.pc_only use_ignite_pool = False if g_phy.data.mgmt_block is not None: mgmt_address_block = netaddr.IPNetwork(g_phy.data.mgmt_block).iter_hosts() mgmt_address_mask = (netaddr.IPNetwork(g_phy.data.mgmt_block)).netmask else: pool = g_phy.data.ignite if pool is not None: if 'mgmt_pool_id' in pool and pool['mgmt_pool_id'] is not None: mgmt_pool_id = pool['mgmt_pool_id'] use_ignite_pool = True if g_phy.data.vpcid_block is not None: vpc_re = "([0-9]+)(-)([0-9]+)" #vpc_id_start = int(re.search(vpc_re, g_phy.data.vpcid_block).group(1)) #vpc_id_end = int(re.search(vpc_re, g_phy.data.vpcid_block).group(3)) #vpc_id_range = vpc_id_end-vpc_id_start vpc_id_range = 1000 # TODO: need to copy across the interface name from edge to the interface # TODO: merge common router code, so end up with three loops: routers, ios # routers, ios_xr routers # TODO: Split out each device compiler into own function # TODO: look for unused code paths here - especially for interface # allocation # store autonetkit_cisco version log.debug("Generating device configurations") from pkg_resources import get_distribution # Copy across indices for external connectors (e.g may want to copy # configs) external_connectors = [n for n in g_phy if n.host == self.host and n.device_type == "external_connector"] for phy_node in external_connectors: DmNode = self.nidb.node(phy_node) DmNode.indices = phy_node.indices g_input = self.anm['input'] managed_switches = [n for n in g_phy.switches() if n.host == self.host and n.device_subtype == "managed"] for phy_node in managed_switches: DmNode = self.nidb.node(phy_node) DmNode.indices = phy_node.indices for phy_node in g_phy.l3devices(host=self.host): loopback_ids = self.loopback_interface_ids() # allocate loopbacks to routes (same for all ios variants) DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.indices = phy_node.indices DmNode.add_stanza("syslog") DmNode.add_stanza('mgmt') if use_ignite_pool == True: mgmt_ip = allocate_pool_entry(mgmt_pool_id,phy_node.name, None) pos_mask = mgmt_ip.find('/') if pos_mask != -1: network = mgmt_ip[:pos_mask] mask = int(mgmt_ip[pos_mask+1:]) else: network = mgmt_ip[:pos_mask] mask = 32 DmNode.mgmt.ip = network + '/' + str(mask) DmNode.mgmt.mask = "" elif g_phy.data.mgmt_block is not None: DmNode.mgmt.ip = mgmt_address_block.next() DmNode.mgmt.mask = mgmt_address_mask # for node_data in phy_node._graph.node: for interface in DmNode.loopback_interfaces(): if interface != DmNode.loopback_zero: interface.id = loopback_ids.next() # numeric ids numeric_int_ids = self.numeric_interface_ids() for interface in DmNode.physical_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id # numeric ids numeric_po_ids = self.numeric_portchannel_ids() for interface in DmNode.portchannel_interfaces(): po_interface = phy_node.interface(interface) interface.numeric_id = int(po_interface.id[po_interface.id.rfind('_')+1:]) po_specified_id = phy_node.interface(interface).specified_id if po_specified_id is not None: interface.id = po_specified_id interface.pc = True for po_mem_int in DmNode.physical_interfaces(): po_mem_interface = phy_node.interface(po_mem_int) if po_mem_interface.id in po_interface.members: po_mem_int.channel_group = interface.numeric_id po_interface_int = po_interface._interface if po_interface_int.has_key('subcat_prot'): if po_interface.subcat_prot == "vpc": po_mem_int.keepalive_port_vpc = True# is a member port of VPC peer link interface.virt_port_channel = True# is a VPC interface DmNode.add_stanza('vpc') if po_interface.subcat_prot == "vpc-member": po_mem_int.member_port_vpc = True interface.vpc_member_id = interface.numeric_id interface.member_vpc = True ##adding rp's if vxlan_global_config is not None and 'rendezvous_point' in vxlan_global_config: for rp in vxlan_global_config['rendezvous_point']: for phy_node in g_phy.l3devices(host=self.host): DmNode = self.nidb.node(phy_node) if phy_node.id == rp['node_id']: rp['node_id'] = DmNode.interfaces[0]._port['ipv4_address'] #from autonetkit.compilers.device.ubuntu import UbuntuCompiler #from autonetkit_cisco.compilers.device.ubuntu import UbuntuCompiler #ubuntu_compiler = UbuntuCompiler(self.nidb, self.anm) for phy_node in g_phy.servers(host=self.host): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.add_stanza("ip") #interface.id = self.numeric_to_interface_label_linux(interface.numeric_id) # print "numeric", interface.numeric_id, interface.id DmNode.ip.use_ipv4 = phy_node.use_ipv4 DmNode.ip.use_ipv6 = phy_node.use_ipv6 # TODO: clean up interface handling numeric_int_ids = self.numeric_interface_ids() for interface in DmNode.physical_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id # numeric ids numeric_po_ids = self.numeric_portchannel_ids() for interface in DmNode.portchannel_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_po_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id # TODO: make this part of the base device compiler, which # server/router inherits # not these are physical interfaces; configure after previous # config steps if use_mgmt_interfaces: mgmt_int = DmNode.add_interface( management=True, description="eth0") mgmt_int_id = "eth0" mgmt_int.id = mgmt_int_id # render route config DmNode = self.nidb.node(phy_node) #ubuntu_compiler.compile(DmNode) if not phy_node.dont_configure_static_routing: DmNode.render.template = os.path.join( "templates", "linux", "static_route.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # TODO: refactor out common logic ios_compiler = IosClassicCompiler(self.nidb, self.anm) host_routers = g_phy.routers(host=self.host) ios_nodes = (n for n in host_routers if n.syntax in ("ios", "ios_xe")) for phy_node in ios_nodes: if (phy_node.devsubtype == "core" or phy_node.devsubtype == "border"): continue DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "ios.mako") to_memory = False if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # TODO: write function that assigns interface number excluding # those already taken # Assign interfaces if phy_node.device_subtype == "IOSv": int_ids = self.interface_ids_ios() numeric_to_interface_label = self.numeric_to_interface_label_ios elif phy_node.device_subtype == "CSR1000v": int_ids = self.interface_ids_csr1000v() numeric_to_interface_label = self.numeric_to_interface_label_ra else: # default if no subtype specified # TODO: need to set default in the load module log.warning("Unexpected subtype %s for %s" % (phy_node.device_subtype, phy_node)) int_ids = self.interface_ids_ios() numeric_to_interface_label = self.numeric_to_interface_label_ios numeric_to_portchannel_interface_label = self.numeric_to_portchannel_interface_label_ios if use_mgmt_interfaces: if phy_node.device_subtype == "IOSv": # TODO: make these configured in the internal config file # for platform/device_subtype keying mgmt_int_id = "GigabitEthernet0/0" if phy_node.device_subtype == "CSR1000v": mgmt_int_id = "GigabitEthernet1" for interface in DmNode.physical_interfaces(): # TODO: use this code block once for all routers if not interface.id: interface.id = numeric_to_interface_label( interface.numeric_id) else: if interface.id[0] == 'e' or interface.id[0] == 'E': #import re port_re = "([a-zA-Z]+)([0-9]+/[0-9]+)" interface.id = "%s %s"%((re.search(port_re,interface.id)).group(1), (re.search(port_re,interface.id)).group(2)) for interface in DmNode.portchannel_interfaces(): # TODO: use this code block once for all routers #if not interface.id: interface.id = numeric_to_portchannel_interface_label( interface.numeric_id) ios_compiler.compile(DmNode) if use_mgmt_interfaces: mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id nxos_compiler = NxOsCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='nx_os'): if (phy_node.devsubtype == "core" or phy_node.devsubtype == "border"): continue DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") if pc_only_config == True: DmNode.render.template = os.path.join("templates", "nexus_os_pc_only.mako") else: DmNode.render.template = os.path.join("templates", "nexus_os.mako") #if to_memory: # DmNode.render.to_memory = True #else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % phy_node.name # Assign interfaces int_ids = self.interface_ids_nxos() numeric_to_interface_label = self.numeric_to_interface_label_nxos numeric_to_portchannel_interface_label = self.numeric_to_portchannel_interface_label_nxos for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_nxos( interface.numeric_id) elif interface.id[0] == 'e' or interface.id[0] == 'E': import re port_re = "([a-zA-Z]+)([0-9]+/[0-9]+)" interface.id = "%s %s"%((re.search(port_re,interface.id)).group(1), (re.search(port_re,interface.id)).group(2)) else: interface.id = 'Ethernet ' + interface.id for interface in DmNode.portchannel_interfaces(): # TODO: use this code block once for all routers #if not interface.id: interface.id = numeric_to_portchannel_interface_label( interface.numeric_id) DmNode.supported_features = ConfigStanza( mpls_te=False, mpls_oam=False, vrf=False) nxos_compiler.compile(DmNode) # TODO: make this work other way around if use_mgmt_interfaces: mgmt_int_id = "mgmt0" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id staros_compiler = StarOsCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='StarOS'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "staros.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_star_os( interface.numeric_id) staros_compiler.compile(DmNode) # TODO: make this work other way around if use_mgmt_interfaces: mgmt_int_id = "ethernet 1/1" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id
def compile(self): self.copy_across_ip_addresses() now = datetime.now() timestamp = now.strftime("%Y%m%d_%H%M%S_%f") dst_folder = os.path.join("rendered", self.host, timestamp, "brocade") log.info("Compiling Brocade for %s" % self.host) g_phy = self.anm['phy'] mgmt_addr_block = netaddr.IPNetwork("192.168.0.0/24").iter_hosts() mgmt_addr_mask = (netaddr.IPNetwork("192.168.0.0/24")).netmask # TODO: this should be all l3 devices not just routers for phy_node in g_phy.l3devices(host=self.host, syntax='brcd_ni'): loopback_ids = self.loopback_interface_ids() dm_node = self.nidb.node(phy_node) dm_node.add_stanza("render") #adding management interface by default dm_node.add_stanza('mgmt') dm_node.mgmt.ip = mgmt_addr_block.next() dm_node.mgmt.mask = mgmt_addr_mask #enabling telnet by default dm_node.add_stanza('telnet') dm_node.telnet = True for interface in dm_node.loopback_interfaces(): if interface != dm_node.loopback_zero: interface.id = loopback_ids.next() # Note this could take external data numeric_int_ids = self.numeric_interface_ids() g_in_node = self.anm['input'].node(phy_node) for interface in dm_node.physical_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id g_in_interface = g_in_node._ports[interface.interface_id] if 'is_member_lag' in g_in_interface: interface.is_member_lag = True if 'is_primary_port' in g_in_interface: interface.is_primary_port = True ni_compiler = BrocadeNICompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='brcd_ni'): dm_node = self.nidb.node(phy_node) dm_node.add_stanza("render") dm_node.render.template = os.path.join("templates", "brcd_ni.mako") dm_node.render.dst_folder = dst_folder dm_node.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_ni() numeric_to_interface_label = self.numeric_to_interface_label_ni for interface in dm_node.physical_interfaces(): if not interface.id: interface.id = numeric_to_interface_label( interface.numeric_id) dm_node.supported_features = ConfigStanza( mpls_te=False, mpls_oam=False, vrf=False) ni_compiler.compile(dm_node)
def compile_devices(self): g_phy = self.anm['phy'] to_memory, use_mgmt_interfaces, dst_folder = self._parameters() if use_mgmt_interfaces: log.debug("Allocating VIRL management interfaces") else: log.debug("Not allocating VIRL management interfaces") # TODO: need to copy across the interface name from edge to the interface # TODO: merge common router code, so end up with three loops: routers, ios # routers, ios_xr routers # TODO: Split out each device compiler into own function # TODO: look for unused code paths here - especially for interface # allocation # store autonetkit_cisco version log.debug("Generating device configurations") from pkg_resources import get_distribution # Copy across indices for external connectors (e.g may want to copy # configs) external_connectors = [ n for n in g_phy if n.host == self.host and n.device_type == "external_connector" ] for phy_node in external_connectors: DmNode = self.nidb.node(phy_node) DmNode.indices = phy_node.indices managed_switches = [ n for n in g_phy.switches() if n.host == self.host and n.device_subtype == "managed" ] for phy_node in managed_switches: DmNode = self.nidb.node(phy_node) DmNode.indices = phy_node.indices for phy_node in g_phy.l3devices(host=self.host): loopback_ids = self.loopback_interface_ids() # allocate loopbacks to routes (same for all ios variants) DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.indices = phy_node.indices for interface in DmNode.loopback_interfaces(): if interface != DmNode.loopback_zero: interface.id = loopback_ids.next() # numeric ids numeric_int_ids = self.numeric_interface_ids() for interface in DmNode.physical_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id #from autonetkit.compilers.device.ubuntu import UbuntuCompiler from autonetkit_cisco.compilers.device.ubuntu import UbuntuCompiler ubuntu_compiler = UbuntuCompiler(self.nidb, self.anm) for phy_node in g_phy.servers(host=self.host): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.add_stanza("ip") # TODO: look at server syntax also, same as for routers for interface in DmNode.physical_interfaces(): phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id #interface.id = self.numeric_to_interface_label_linux(interface.numeric_id) # print "numeric", interface.numeric_id, interface.id DmNode.ip.use_ipv4 = phy_node.use_ipv4 DmNode.ip.use_ipv6 = phy_node.use_ipv6 # TODO: clean up interface handling numeric_int_ids = self.numeric_interface_ids() for interface in DmNode.physical_interfaces(): phy_int = phy_node.interface(interface) phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id # TODO: make this part of the base device compiler, which # server/router inherits # not these are physical interfaces; configure after previous # config steps if use_mgmt_interfaces: mgmt_int = DmNode.add_interface(management=True, description="eth0") mgmt_int_id = "eth0" mgmt_int.id = mgmt_int_id # render route config DmNode = self.nidb.node(phy_node) ubuntu_compiler.compile(DmNode) if not phy_node.dont_configure_static_routing: DmNode.render.template = os.path.join("templates", "linux", "static_route.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # TODO: refactor out common logic ios_compiler = IosClassicCompiler(self.nidb, self.anm) host_routers = g_phy.routers(host=self.host) ios_nodes = (n for n in host_routers if n.syntax in ("ios", "ios_xe")) for phy_node in ios_nodes: DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "ios.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # TODO: write function that assigns interface number excluding # those already taken # Assign interfaces if phy_node.device_subtype == "IOSv": int_ids = self.interface_ids_ios() numeric_to_interface_label = self.numeric_to_interface_label_ios elif phy_node.device_subtype == "CSR1000v": int_ids = self.interface_ids_csr1000v() numeric_to_interface_label = self.numeric_to_interface_label_ra else: # default if no subtype specified # TODO: need to set default in the load module log.warning("Unexpected subtype %s for %s" % (phy_node.device_subtype, phy_node)) int_ids = self.interface_ids_ios() numeric_to_interface_label = self.numeric_to_interface_label_ios if use_mgmt_interfaces: if phy_node.device_subtype == "IOSv": # TODO: make these configured in the internal config file # for platform/device_subtype keying mgmt_int_id = "GigabitEthernet0/0" if phy_node.device_subtype == "CSR1000v": mgmt_int_id = "GigabitEthernet1" for interface in DmNode.physical_interfaces(): # TODO: use this code block once for all routers if not interface.id: interface.id = numeric_to_interface_label( interface.numeric_id) ios_compiler.compile(DmNode) if use_mgmt_interfaces: mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id try: from autonetkit_cisco.compilers.device.cisco import IosXrCompiler ios_xr_compiler = IosXrCompiler(self.nidb, self.anm) except ImportError: ios_xr_compiler = IosXrCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='ios_xr'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "ios_xr", "router.conf.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_ios_xr() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_ios_xr( interface.numeric_id) ios_xr_compiler.compile(DmNode) if use_mgmt_interfaces: mgmt_int_id = "mgmteth0/0/CPU0/0" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id nxos_compiler = NxOsCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='nx_os'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "nx_os.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_nxos( interface.numeric_id) DmNode.supported_features = ConfigStanza(mpls_te=False, mpls_oam=False, vrf=False) nxos_compiler.compile(DmNode) # TODO: make this work other way around if use_mgmt_interfaces: mgmt_int_id = "mgmt0" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id staros_compiler = StarOsCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='StarOS'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "staros.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_star_os( interface.numeric_id) staros_compiler.compile(DmNode) # TODO: make this work other way around if use_mgmt_interfaces: mgmt_int_id = "ethernet 1/1" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id
def compile_devices(self): g_phy = self.anm['phy'] to_memory, use_mgmt_interfaces, dst_folder = self._parameters() if use_mgmt_interfaces: log.debug("Allocating VIRL management interfaces") else: log.debug("Not allocating VIRL management interfaces") # TODO: need to copy across the interface name from edge to the interface # TODO: merge common router code, so end up with three loops: routers, ios # routers, ios_xr routers # TODO: Split out each device compiler into own function # TODO: look for unused code paths here - especially for interface # allocation # store autonetkit_cisco version log.debug("Generating device configurations") from pkg_resources import get_distribution # Copy across indices for external connectors (e.g may want to copy # configs) external_connectors = [n for n in g_phy if n.host == self.host and n.device_type == "external_connector"] for phy_node in external_connectors: DmNode = self.nidb.node(phy_node) DmNode.indices = phy_node.indices for phy_node in g_phy.l3devices(host=self.host): loopback_ids = self.loopback_interface_ids() # allocate loopbacks to routes (same for all ios variants) DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.indices = phy_node.indices for interface in DmNode.loopback_interfaces(): if interface != DmNode.loopback_zero: interface.id = loopback_ids.next() # numeric ids numeric_int_ids = self.numeric_interface_ids() for interface in DmNode.physical_interfaces(): phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id #from autonetkit.compilers.device.ubuntu import UbuntuCompiler from autonetkit_cisco.compilers.device.ubuntu import UbuntuCompiler ubuntu_compiler = UbuntuCompiler(self.nidb, self.anm) for phy_node in g_phy.servers(host=self.host): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.add_stanza("ip") # TODO: look at server syntax also, same as for routers for interface in DmNode.physical_interfaces(): phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id #interface.id = self.numeric_to_interface_label_linux(interface.numeric_id) # print "numeric", interface.numeric_id, interface.id DmNode.ip.use_ipv4 = phy_node.use_ipv4 DmNode.ip.use_ipv6 = phy_node.use_ipv6 # TODO: clean up interface handling numeric_int_ids = self.numeric_interface_ids() for interface in DmNode.physical_interfaces(): phy_int = phy_node.interface(interface) phy_numeric_id = phy_node.interface(interface).numeric_id if phy_numeric_id is None: # TODO: remove numeric ID code interface.numeric_id = numeric_int_ids.next() else: interface.numeric_id = int(phy_numeric_id) phy_specified_id = phy_node.interface(interface).specified_id if phy_specified_id is not None: interface.id = phy_specified_id # TODO: make this part of the base device compiler, which # server/router inherits # not these are physical interfaces; configure after previous # config steps if use_mgmt_interfaces: mgmt_int = DmNode.add_interface( management=True, description="eth0") mgmt_int_id = "eth0" mgmt_int.id = mgmt_int_id # render route config DmNode = self.nidb.node(phy_node) ubuntu_compiler.compile(DmNode) if not phy_node.dont_configure_static_routing: DmNode.render.template = os.path.join( "templates", "linux", "static_route.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # TODO: refactor out common logic ios_compiler = IosClassicCompiler(self.nidb, self.anm) host_routers = g_phy.routers(host=self.host) ios_nodes = (n for n in host_routers if n.syntax in ("ios", "ios_xe")) for phy_node in ios_nodes: DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "ios.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # TODO: write function that assigns interface number excluding # those already taken # Assign interfaces if phy_node.device_subtype == "IOSv": int_ids = self.interface_ids_ios() numeric_to_interface_label = self.numeric_to_interface_label_ios elif phy_node.device_subtype == "CSR1000v": int_ids = self.interface_ids_csr1000v() numeric_to_interface_label = self.numeric_to_interface_label_ra else: # default if no subtype specified # TODO: need to set default in the load module log.warning("Unexpected subtype %s for %s" % (phy_node.device_subtype, phy_node)) int_ids = self.interface_ids_ios() numeric_to_interface_label = self.numeric_to_interface_label_ios if use_mgmt_interfaces: if phy_node.device_subtype == "IOSv": # TODO: make these configured in the internal config file # for platform/device_subtype keying mgmt_int_id = "GigabitEthernet0/0" if phy_node.device_subtype == "CSR1000v": mgmt_int_id = "GigabitEthernet1" for interface in DmNode.physical_interfaces(): # TODO: use this code block once for all routers if not interface.id: interface.id = numeric_to_interface_label( interface.numeric_id) ios_compiler.compile(DmNode) if use_mgmt_interfaces: mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id try: from autonetkit_cisco.compilers.device.cisco import IosXrCompiler ios_xr_compiler = IosXrCompiler(self.nidb, self.anm) except ImportError: ios_xr_compiler = IosXrCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='ios_xr'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join( "templates", "ios_xr", "router.conf.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_ios_xr() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_ios_xr( interface.numeric_id) ios_xr_compiler.compile(DmNode) if use_mgmt_interfaces: mgmt_int_id = "mgmteth0/0/CPU0/0" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id nxos_compiler = NxOsCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='nx_os'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "nx_os.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_nxos( interface.numeric_id) DmNode.supported_features = ConfigStanza( mpls_te=False, mpls_oam=False, vrf=False) nxos_compiler.compile(DmNode) # TODO: make this work other way around if use_mgmt_interfaces: mgmt_int_id = "mgmt0" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id staros_compiler = StarOsCompiler(self.nidb, self.anm) for phy_node in g_phy.routers(host=self.host, syntax='StarOS'): DmNode = self.nidb.node(phy_node) DmNode.add_stanza("render") DmNode.render.template = os.path.join("templates", "staros.mako") if to_memory: DmNode.render.to_memory = True else: DmNode.render.dst_folder = dst_folder DmNode.render.dst_file = "%s.conf" % naming.network_hostname( phy_node) # Assign interfaces int_ids = self.interface_ids_nxos() for interface in DmNode.physical_interfaces(): if not interface.id: interface.id = self.numeric_to_interface_label_star_os( interface.numeric_id) staros_compiler.compile(DmNode) # TODO: make this work other way around if use_mgmt_interfaces: mgmt_int_id = "ethernet 1/1" mgmt_int = DmNode.add_interface(management=True) mgmt_int.id = mgmt_int_id
def compile(self): self.copy_across_ip_addresses() log.info("Compiling Netkit for %s" % self.host) g_phy = self.anm['phy'] quagga_compiler = QuaggaCompiler(self.nidb, self.anm) # todo: set platform render lab_topology = self.nidb.topology(self.host) lab_topology.render2 = PlatformRender() # TODO: this should be all l3 devices not just routers for phy_node in g_phy.l3devices(host=self.host, syntax='quagga'): folder_name = naming.network_hostname(phy_node) dm_node = self.nidb.node(phy_node) dm_node.add_stanza("render") # TODO: order by folder and file template src/dst dm_node.render.base = os.path.join("templates", "quagga") dm_node.render.template = os.path.join("templates", "netkit_startup.mako") dm_node.render.dst_folder = os.path.join("rendered", self.host, "netkit") dm_node.render.base_dst_folder = os.path.join("rendered", self.host, "netkit", folder_name) dm_node.render.dst_file = "%s.startup" % folder_name dm_node.render.custom = { 'abc': 'def.txt' } render2 = NodeRender() # TODO: dest folder also needs to be able to accept a list # TODO: document that use a list so can do native os.path.join on # target platform render2.add_folder(["templates", "quagga"], folder_name) render2.add_file( ("templates", "netkit_startup.mako"), "%s.startup" % folder_name) dm_node.render2 = render2 lab_topology.render2.add_node(dm_node) # lab_topology.render2_hosts.append(phy_node) # allocate zebra information dm_node.add_stanza("zebra") if dm_node.is_router(): dm_node.zebra.password = "******" hostname = folder_name if hostname[0] in string.digits: hostname = "r" + hostname dm_node.hostname = hostname # can't have . in quagga hostnames dm_node.add_stanza("ssh") # TODO: make this set based on presence of key dm_node.ssh.use_key = True # Note this could take external data int_ids = itertools.count(0) for interface in dm_node.physical_interfaces(): numeric_id = int_ids.next() interface.numeric_id = numeric_id interface.id = self.index_to_int_id(numeric_id) # and allocate tap interface dm_node.add_stanza("tap") dm_node.tap.id = self.index_to_int_id(int_ids.next()) quagga_compiler.compile(dm_node) if dm_node.bgp: dm_node.bgp.debug = True static_routes = [] dm_node.zebra.static_routes = static_routes # and lab.conf self.allocate_tap_ips() self.allocate_lab_topology()