Last active
August 24, 2019 16:59
-
-
Save clay584/d76858de7829e35e2afd54de9713a07a to your computer and use it in GitHub Desktop.
Napalm example
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
#!/usr/bin/env python3 | |
from napalm import get_network_driver | |
from getpass import getpass | |
from netmiko import NetMikoAuthenticationException | |
from napalm.base.exceptions import ConnectionException | |
from pprint import pprint | |
username = input('username: ') | |
password = getpass('password: ') | |
driver = get_network_driver('ios') | |
with open('devices.txt','r') as switch_db: | |
for switch in switch_db: | |
#set up to connect to a switch from switch_db | |
try: | |
with driver(switch, username, password, optional_args={'port': 8181}) as device: | |
pprint(device.get_facts()) | |
except NetMikoAuthenticationException: | |
print('Authentication Error!') | |
except ConnectionException: | |
print(f'Could not connect to {switch}') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated to handle the errors a bit better.