Package: netwalk
NetwalkNetwalk is a Python library born out of a large remadiation project aimed at making network device discovery and management as fast and painless as possible.InstallationCan be installed via pip withpip install netwalkExtrasA collection of scripts with extra features and examples is stored in theextrasfolderCode qualityA lot of the code is covered by tests. More will be added in the futureFabricThis object type defines an entire switched network and can be manually populated, have switches added one by one or you can give it one or more seed devices and it will go and scan everything for you.Auto scanning example:fromnetwalkimportFabricsitename=Fabric()sitename.init_from_seed_device(seed_hosts=["10.10.10.1"],credentials=[("cisco","cisco"),("customer","password")]napalm_optional_args=[{'secret':'cisco'},{'transport':'telnet'}])This code will start searching from device 10.10.10.1 and will try to log in via SSH with cisco/cisco and then customer/password.
Once connected to the switch it will pull and parse the running config, the mac address table and the cdp neighbours, then will start cycling through all neighbours recursively until the entire fabric has been discoveredNote: you may also pass a list ofnapalm_optional_args, check theNAPALM optional args guidefor explanation and examplesManual addition of switchesYou can tell Fabric to discover another switch on its own or you can add aSwitchobject to.devices. WHichever way, do not forget to callrefresh_global_informationto recalculate neighborships and global mac address tableExamplesitename.add_switch(host="10.10.10.1",credentials=[("cisco","cisco"))sitename.refresh_global_information()Note: you may also pass a list ofnapalm_optional_args, check theoptional args guidefor explanation and examplesStructuresitenamewill now contain two main attributes:switches, a dictionary of{'hostname': Switch}mac_table, another dictionary containing a list of all macs in the fabric, the interface closest to themSwitchThis object defines a switch. It can be created in two ways:Automatic connectionfromnetwalkimportSwitchsw01=Switch(hostname="10.10.10.1")sw01.retrieve_data(username="cisco",password="cisco"})Note: you may also pass a list ofnapalm_optional_args, check theoptional args guidefor explanation and examplesThis will connect to the switch and pull all the data much likeadd_switch()does inFabricInit from show runYou may also generate the Switch device from a show run you have extracted somewhere else. This will not give you mac address table or neighborship discovery but will generate all Interfaces in the switchfromnetwalkimportSwitchshowrun="""int gi 0/1switchport mode access...int gi 0/24switchport mode trunk"""sw01=Switch(hostname="10.10.10.1",config=showrun)StructureASwitchobject has the following attributes:hostname: the IP or hostname to connect toconfig: string containing plain text show runinterfaces: dictionary of{'interface name', Interface}}mac_table: a dictionary containing the switch's mac address tableInterfaceAn Interface object defines a switched interface ("switchport" in Cisco language) and can hold data about its configuration such as:namedescriptionmode: either "access" or "trunk"allowed_vlan: aset()of vlans to tagnative_vlanvoice_vlanswitch: pointer to parent Switchis_up: if the interface is activeis_enabled: shutdown ot notconfig: its configurationmac_count: number of MACs behind ittype_edge: also known as "portfast"bpduguardPrinting an interface yelds its configuration based on its current attributesTrickCheck a trunk filter is equal on both sidesassertint.allowed_vlan==int.neighbors[0].allowed_vlanCheck a particular host is in vlan 10fromnetaddrimportEUIhost_mac=EUI('00:01:02:03:04:05')assertfabric.mac_table[host_mac]['interface'].native_vlan==10