from pprint import pprint from time import sleep import daiquiri from genie.testbed import load from genie.utils.diff import Diff from pyats.datastructures import ListDict from devicemanagement import utils LOGGER = daiquiri.getLogger(__name__) # output = """ # Protocol Address Age (min) Hardware Addr Type Interface # Internet 10.122.41.129 47 001a.6c78.e7ff ARPA GigabitEthernet1 # Internet 10.122.41.169 - 0050.569f.840b ARPA GigabitEthernet1 # Internet 10.122.41.171 208 0050.569f.7e22 ARPA GigabitEthernet1 # Internet 10.122.41.186 228 0050.569f.3343 ARPA GigabitEthernet1 # Internet 172.20.3.14 - 0050.569f.0e3d ARPA GigabitEthernet2 # Internet 172.20.3.15 84 0050.569f.2637 ARPA GigabitEthernet2 # Internet 172.20.3.16 73 0050.569f.98f8 ARPA GigabitEthernet2 # Internet 172.20.3.17 128 0050.569f.1b6f ARPA GigabitEthernet2 # Internet 172.20.3.18 109 0050.569f.2ac9 ARPA GigabitEthernet2 # Internet 172.20.3.250 235 0050.569f.ed6d ARPA GigabitEthernet2 # """ uut = { "devices": { "uut": { "ip": "10.122.41.169", "username": "luis", "password": "Lu!s2020", "os": "ios", "protocol": "ssh", "port": 22, } } } testbed = load(uut) testbed.devices["uut"].connect( learn_hostname=True, init_exec_commands=[], init_config_commands=[], log_stdout=False, ) # pre_check = testbed.devices["uut"].parse("show arp", output=output) # output = """ # Protocol Address Age (min) Hardware Addr Type Interface # Internet 10.122.41.129 47 001a.6c78.e7fa ARPA GigabitEthernet1 # Internet 10.122.41.169 - 0050.569f.840b ARPA GigabitEthernet1 # Internet 10.122.41.171 208 0050.569f.7e22 ARPA GigabitEthernet1 # Internet 172.20.3.14 - 0050.569f.0e3d ARPA GigabitEthernet2 # Internet 10.122.41.186 228 0050.569f.3343 ARPA GigabitEthernet1 # Internet 172.20.3.15 84 0050.569f.2637 ARPA GigabitEthernet2 # Internet 172.20.3.16 73 0050.569f.98f8 ARPA GigabitEthernet2 # Internet 172.20.3.17 128 0050.569f.1b6f ARPA GigabitEthernet2 # Internet 172.20.3.18 109 0050.569f.2ac9 ARPA GigabitEthernet2 # Internet 172.20.3.250 235 0050.569f.ed6d ARPA GigabitEthernet2 # """ # post_check = testbed.devices["uut"].parse("show arp", output=output) # dd = Diff(pre_check, post_check) # dd.findDiff() # print(dd) # show_ip_int_brief = testbed.devices["uut"].parse("show ip int brief") # pprint(show_ip_int_brief) # pprint(utils.ListOfParsedCommands(show_ip_int_brief, "interface")) commands = ["show inventory"] commands_with_list = [ # "show arp", # "show ip int brief", # "show inventory", # "show interfaces description", # "show ip mroute", # "show ip route", # "show cdp neighbors", # "show aliases", "show line", ] for command in commands_with_list: print("======== Command: {} =========".format(command)) print("======== Parsed =========") parsed_command = testbed.devices["uut"].parse(command) pprint(parsed_command) print("======== ListDict =========") pprint(ListDict(parsed_command)) print("======== ListOfParsed =========") pprint(utils.ListOfParsedCommands(parsed_command))