Created
May 25, 2022 16:17
-
-
Save userlerueda/6e63597127b3d93fedbe737703191b61 to your computer and use it in GitHub Desktop.
pyATS Commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment