-
Notifications
You must be signed in to change notification settings - Fork 1
/
jradmin_test.py
25 lines (20 loc) · 990 Bytes
/
jradmin_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Python script for junior admin users to run show commands. Note: need to ensure default file username is set to jradmin
import getpass
import sys
from nornir import InitNornir
from nornir_scrapli.tasks import send_command
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.
commands = input ("\nEnter Commands you want to send to the devices. Ensure they are comma seperated: ")
cmds = commands.split (",")
def push_show_commands(task):
for cmd in cmds:
task.run(task=send_command, command=cmd)
results = nr.run(task=push_show_commands)
print_result(results)