Skip to content
Permalink
Browse files
Migrate from github.com
  • Loading branch information
sbyrnes committed Aug 30, 2023
0 parents commit 7d4516f03ec89cd14400f3d97678ec364697cf35
Showing 52 changed files with 3,051 additions and 0 deletions.
Empty file.
Empty file.
@@ -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"
)
@@ -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

0 comments on commit 7d4516f

Please sign in to comment.