Skip to content

Instantly share code, notes, and snippets.

@clay584
Last active August 24, 2019 16:59
Show Gist options
  • Save clay584/d76858de7829e35e2afd54de9713a07a to your computer and use it in GitHub Desktop.
Save clay584/d76858de7829e35e2afd54de9713a07a to your computer and use it in GitHub Desktop.
Napalm example
#!/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}')
@clay584
Copy link
Author

clay584 commented Aug 24, 2019

updated to handle the errors a bit better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment