Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
sbyrnes committed Feb 28, 2024
0 parents commit ecedbc3
Show file tree
Hide file tree
Showing 31 changed files with 2,856 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.DS_Store
Empty file.
Empty file.
@@ -0,0 +1,26 @@
# 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,30 @@
# pip install --user textfsm
# pip install --user netmiko
import json
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 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 ecedbc3

Please sign in to comment.