-
Notifications
You must be signed in to change notification settings - Fork 1
/
nornir-multi-showcmd.py
30 lines (27 loc) · 1.36 KB
/
nornir-multi-showcmd.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
25
26
27
28
29
30
#python script using nornir_scrapli to send multiple show commands
#user will be prompted to add show commands on screen
import getpass
from nornir import InitNornir
from nornir_scrapli.tasks import send_command
from nornir_utils.plugins.functions import print_result
#importing send_commands from nornir_scrapli to send multiple commands
nr = InitNornir(config_file="config4.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 wish to send (comma seperated): ")
cmds = commands.split(",")
#above is going to display Enter commands on the screen and pass commands entered
#to the function below
def push_show_commands(task):
for cmd in cmds:
task.run(task=send_command, command=cmd)
#above function is going to take the commands input by the user and
# use send_commands task to send those commands to the host
results = nr.run(task=push_show_commands)
#above line is setting an object results that is aligned to the task output
print_result(results)
#finally we print the data in the results object using print_results