-
Notifications
You must be signed in to change notification settings - Fork 1
/
dryruntest.py
24 lines (20 loc) · 1.2 KB
/
dryruntest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Python script using napalm dry_run to validate configuration on hosts before being applied
# Note: SCP server must be enabled to use Napalm (i.e. ip scp server enable)
import getpass
from nornir import InitNornir
from nornir_napalm.plugins.tasks import napalm_configure
from nornir_utils.plugins.functions import print_result
nr = InitNornir(config_file="config.yaml")
#The above line is telling nornir where the config file is located
user = input("Enter your username: ")
password = getpass.getpass(prompt="Enter your password: ")
nr.inventory.defaults.username = user
nr.inventory.defaults.password = password
#The above lines will prompt the user to enter their username and password and use that input to connect to the devices
def dryrun_test(task):
task.run(task=napalm_configure, filename="napalm-config.txt", dry_run=True)
# creating the function dryrun_test and using napalm_configure to send configuration from a text file
# note that dry_run=True which means Napalm will test and validate the configuration will be accepted by the hosts
# but will not actually apply it. You can change dry_run=False to apply the configuration once you have validated it
results = nr.run(task=dryrun_test)
print_result(results)