Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit
- Loading branch information
0 parents
commit ecedbc3
Showing
31 changed files
with
2,856 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions
26
1-reading-network-configuration/answers/exercise1/1_netmiko_show_interfaces_raw.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
) |
30 changes: 30 additions & 0 deletions
30
1-reading-network-configuration/answers/exercise1/2_netmiko_show_interfaces_textfsm.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.