def test_ip_drawing_yed_data_dict_group_links(): data = { "Cisco_IOS": [ """ switch_1# show run interfaces interface Loopback0 description Routing Loopback ip address 10.123.0.4 255.255.255.255 ! interface TenGigabitEthernet1/1/3 description to SWITCH_2 vrf VRF1 link 1 vrf forwarding VRF2 ip address 10.123.2.3 255.255.255.254 ! interface TenGigabitEthernet1/1/4 description to SWITCH_2 vrf VRF1 link 2 vrf forwarding VRF2 ip address 10.123.2.4 255.255.255.254 ! interface TenGigabitEthernet1/1/5 description to SWITCH_3 ip address 10.1.33.1 255.255.255.0 ! interface TenGigabitEthernet1/1/7 description to SWITCH_2 shared subnet ip address 10.1.234.1 255.255.255.0 ! interface Vlan123 description Workstations Vlan vrf forwarding CORP ip address 10.123.111.1 255.255.255.0 ip address 10.123.222.1 255.255.255.0 secondary ip address 10.123.233.1 255.255.255.0 secondary """, """ switch_2# show run interfaces interface Loopback0 description Routing Loopback ip address 10.123.0.5 255.255.255.255 ! interface GigabitEthernet1/3 description to SWITCH_1 link 1 vrf forwarding VRF1 ip address 10.123.2.2 255.255.255.254 ! interface GigabitEthernet1/4 description to SWITCH_1 links 2 vrf forwarding VRF1 ip address 10.123.2.5 255.255.255.254 ! interface TenGigabitEthernet1/1/71 description to SWITCH_2 shared subnet ip address 10.1.234.2 255.255.255.0 ! interface Vlan11 description Workstations Vlan vrf forwarding Staff Workstations ip address 10.11.11.1 255.255.255.0 ! interface Vlan22 description Workstations Vlan vrf forwarding Staff Phones ip address 10.22.22.1 255.255.255.0 """ ] } config = {"group_links": True} drawing = create_yed_diagram() drawer = ip_drawer(drawing, config) drawer.work(data) drawer.drawing.dump_file( filename="test_ip_drawing_yed_data_dict_group_links.graphml", folder="./Output/") with open("./Output/test_ip_drawing_yed_data_dict_group_links.graphml" ) as produced: with open( "./Output/should_be_test_ip_drawing_yed_data_dict_group_links.graphml" ) as should_be: assert produced.read() == should_be.read()
def cli_tool(): # form argparser menu: description_text = """Version: {}{}""".format(__version__, cli_help) argparser = argparse.ArgumentParser( description="N2G CLI, version {}".format(__version__), formatter_class=argparse.RawDescriptionHelpFormatter, ) run_options = argparser.add_argument_group(description=description_text) #----------------------------------------------------------------------------- # General options #----------------------------------------------------------------------------- run_options.add_argument( "-d", "--data", action="store", dest="DATA", default="", type=str, help=argparse.SUPPRESS, ) run_options.add_argument( "-f", "--folder", action="store", dest="FOLDER", default="./Output/", type=str, help=argparse.SUPPRESS, ) run_options.add_argument( "-fn", "--filename", action="store", dest="FILENAME", default=None, type=str, help=argparse.SUPPRESS, ) run_options.add_argument( "-m", "--module", action="store", dest="MODULE", default="yed", type=str, help=argparse.SUPPRESS, ) #----------------------------------------------------------------------------- # CDP and LLDP (L2) options #----------------------------------------------------------------------------- run_options.add_argument( "-L2", action="store_true", dest="L2", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-L2-add-lag", action="store_true", dest="L2_add_lag", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-L2-group-links", action="store_true", dest="L2_group_links", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-L2-add-connected", action="store_true", dest="L2_add_connected", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-L2-combine-peers", action="store_true", dest="L2_combine_peers", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-L2-platforms", action="store", dest="L2_platforms", default="_all_", type=str, help=argparse.SUPPRESS, ) #----------------------------------------------------------------------------- # IP drawer options #----------------------------------------------------------------------------- run_options.add_argument( "-IP", action="store_true", dest="IP", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-IP-group-links", action="store_true", dest="IP_group_links", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-IP-lbl-intf", action="store_true", dest="IP_lbl_intf", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-IP-lbl-vrf", action="store_true", dest="IP_lbl_vrf", default=False, help=argparse.SUPPRESS, ) run_options.add_argument( "-IP-add-arp", action="store_true", dest="IP_add_arp", default=False, help=argparse.SUPPRESS, ) #----------------------------------------------------------------------------- # Parse arguments #----------------------------------------------------------------------------- args = argparser.parse_args() # general arguments DATA = args.DATA # string, OS path to data files to process FOLDER = args.FOLDER # OS path to folder to save results into FILENAME = args.FILENAME # output filename MODULE = args.MODULE # CDP and LLDP drawer arguments L2 = args.L2 L2_add_lag = args.L2_add_lag L2_group_links = args.L2_group_links L2_add_connected = args.L2_add_connected L2_platforms = args.L2_platforms L2_combine_peers = args.L2_combine_peers # IP drawer arguments IP = args.IP IP_group_links = args.IP_group_links IP_lbl_intf = args.IP_lbl_intf IP_lbl_vrf = args.IP_lbl_vrf IP_add_arp = args.IP_add_arp ext = "graphml" if MODULE == "yed" else "drawio" if not FILENAME: FILENAME = 'output_{}.{}'.format(ctime, ext) elif not FILENAME.endswith(ext): FILENAME = "{}.{}".format(FILENAME, ext) if not os.path.exists(FOLDER): os.mkdir(FOLDER) if MODULE == "yed": drawing = create_yed_diagram() if MODULE == "drawio": drawing = create_drawio_diagram() # add CDP and LLDP to diagram if L2: config = { "add_interfaces_data": True, "group_links": L2_group_links, "add_lag": L2_add_lag, "add_all_connected": L2_add_connected, "platforms": [i.strip() for i in L2_platforms.split(",")], "combine_peers": L2_combine_peers } drawer = layer_2_drawer(drawing, config) drawer.work(DATA) # add IP and Subnets nodes and links to diagram if IP: config = { "group_links": IP_group_links, "label_interface": IP_lbl_intf, "label_vrf": IP_lbl_vrf, "add_arp": IP_add_arp } drawer = ip_drawer(drawing, config) drawer.work(DATA) # save results in file drawing.dump_file(filename=FILENAME, folder=FOLDER)
def test_ip_drawing_yed_data_dict_add_arp_and_fhrp(): data = { "Cisco_IOS": [ """ switch_1# show run interfaces interface TenGigabitEthernet1/1/5 description to SWITCH_3 ip address 10.1.33.1 255.255.255.0 ! interface TenGigabitEthernet1/1/3 description to SWITCH_2 vrf VRF1 link 1 vrf forwarding VRF2 ip address 10.123.2.3 255.255.255.254 ! interface TenGigabitEthernet1/1/4 description to SWITCH_2 vrf VRF1 link 2 vrf forwarding VRF2 ip address 10.123.2.4 255.255.255.254 ! interface TenGigabitEthernet1/1/7 description to SWITCH_2 shared subnet ip address 10.1.234.1 255.255.255.0 standby 1 10.1.234.99 ! interface Vlan123 description Workstations Vlan vrf forwarding CORP ip address 10.123.111.1 255.255.255.0 ip address 10.123.222.1 255.255.255.0 secondary ip address 10.123.233.1 255.255.255.0 secondary switch_1# show ip arp Internet 10.123.111.1 - d094.6643.1111 ARPA Vlan123 Internet 10.123.111.3 0 0008.e3ff.1333 ARPA Vlan123 Internet 10.123.111.4 106 d867.d9b7.1444 ARPA Vlan123 Internet 10.123.111.5 106 d867.d9b7.1555 ARPA Vlan123 Internet 10.123.233.1 - 0008.e3ff.2111 ARPA Vlan123 Internet 10.123.233.3 166 d867.d9b7.2333 ARPA Vlan123 Internet 10.123.233.4 31 0008.e3ff.2444 ARPA Vlan123 Internet 10.123.233.6 31 0008.e3ff.2666 ARPA Vlan123 Internet 10.1.234.1 - d867.d9b7.1111 ARPA TenGigabitEthernet1/1/7 Internet 10.1.234.2 31 0008.e3ff.1234 ARPA TenGigabitEthernet1/1/7 Internet 10.1.234.3 31 0008.e3ff.4321 ARPA TenGigabitEthernet1/1/7 Internet 10.1.234.99 - 00ac.0007.001a ARPA TenGigabitEthernet1/1/7 """, """ switch_2# show run interfaces interface TenGigabitEthernet1/1/71 description to SWITCH_2 shared subnet ip address 10.1.234.2 255.255.255.0 standby 1 10.1.234.99 ! interface GigabitEthernet1/3 description to SWITCH_1 link 1 vrf forwarding VRF1 ip address 10.123.2.2 255.255.255.254 ! interface GigabitEthernet1/4 description to SWITCH_1 links 2 vrf forwarding VRF1 ip address 10.123.2.5 255.255.255.254 ! interface Vlan11 description Workstations Vlan vrf forwarding Staff Workstations ip address 10.11.11.1 255.255.255.0 ! interface Vlan22 description Workstations Vlan vrf forwarding Staff Phones ip address 10.22.22.1 255.255.255.0 switch_2# show ip arp Internet 10.22.22.1 - d094.7890.1111 ARPA Vlan22 Internet 10.22.22.3 0 0008.7890.1333 ARPA Vlan22 Internet 10.22.22.4 106 d867.7890.1444 ARPA Vlan22 Internet 10.1.234.1 5 d867.d9b7.1111 ARPA TenGigabitEthernet1/1/71 Internet 10.1.234.2 - 0008.e3ff.1234 ARPA TenGigabitEthernet1/1/71 Internet 10.1.234.3 78 0008.e3ff.4321 ARPA TenGigabitEthernet1/1/71 Internet 10.1.234.99 5 00ac.0007.001a ARPA TenGigabitEthernet1/1/71 """ ] } config = { "add_arp": True, "add_fhrp": True, # "collapse_ptp": True } drawing = create_yed_diagram() drawer = ip_drawer(drawing, config) drawer.work(data) drawer.drawing.dump_file( filename="test_ip_drawing_yed_data_dict_add_arp_and_fhrp.graphml", folder="./Output/") with open("./Output/test_ip_drawing_yed_data_dict_add_arp_and_fhrp.graphml" ) as produced: with open( "./Output/should_be_test_ip_drawing_yed_data_dict_add_arp_and_fhrp.graphml" ) as should_be: assert produced.read() == should_be.read() # test_ip_drawing_yed_data_dict_add_arp_and_fhrp()