Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
52 changed files
with
3,051 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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
@@ -0,0 +1,29 @@ | ||
# pip install --user netmiko | ||
from netmiko import Netmiko | ||
|
||
username = "clab" | ||
password = "clab@123" | ||
device_type = "cisco_xr" | ||
hosts = ["172.16.30.2", "172.16.30.3"] | ||
command_to_run = "show int brief" | ||
|
||
for host in hosts: | ||
# Create a variable that represents an SSH connection to our router. | ||
connection = Netmiko( | ||
username=username, | ||
password=password, | ||
device_type=device_type, | ||
ip=host | ||
) | ||
|
||
# Send a command to the router, and get back the raw output | ||
raw_output = connection.send_command(command_to_run) | ||
|
||
# The "really raw" output has '\n' characters appear instead of a real carriage return. | ||
# Converting them into carriage returns will make it a little more readable for this demo. | ||
raw_output = raw_output.replace("\\n", "\n") | ||
|
||
print( | ||
f"### This is the raw output from {host}, without any parsing: ###\n", | ||
raw_output + "\n" | ||
) |
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
@@ -0,0 +1,32 @@ | ||
# pip install --user textfsm | ||
# pip install --user netmiko | ||
import json | ||
from netmiko import Netmiko | ||
from pprint import pprint | ||
|
||
username = "clab" | ||
password = "clab@123" | ||
device_type = "cisco_xr" | ||
hosts = ["172.16.30.2", "172.16.30.3"] | ||
command_to_run = "show int brief" | ||
|
||
for host in hosts: | ||
# Create a variable that represents an SSH connection to our router. | ||
connection = Netmiko( | ||
username=username, | ||
password=password, | ||
device_type=device_type, | ||
ip=host, | ||
) | ||
|
||
# Send a command to the router, and get back the output "dictionaried" by textfsm. | ||
textfsm_output = connection.send_command(command_to_run, use_textfsm=True) | ||
|
||
print(f"### This is the TextFSM output from {host}: ###") | ||
print(textfsm_output) | ||
print("\n") # Add extra space between our outputs for each host | ||
|
||
|
||
print(f"### This is the TextFSM output from {host}, but JSON-formatted: ###") | ||
print(json.dumps(textfsm_output, indent=4)) # indent for readability | ||
print("\n") # Add extra space between our outputs for each host |
Oops, something went wrong.