forked from geordie12311/nornir-python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnornnetmikio-txtfsm-parser.py
More file actions
20 lines (18 loc) · 945 Bytes
/
nornnetmikio-txtfsm-parser.py
File metadata and controls
20 lines (18 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#python script using textfsm and nornir_netmiko to output the show command
#this script is using the command "show clock" to output structured data format.
import getpass
from nornir import InitNornir
from nornir_netmiko.tasks import netmiko_send_command
from nornir_utils.plugins.functions import print_result
nr = InitNornir(config_file="config.yaml")
password = getpass.getpass()
nr.inventory.defaults.password = password
#above section is initialising nornir and using getpass to prompt the user
#to enter their password
def test_this(task):
clock_results = task.run(task=netmiko_send_command, command_string="show clock", use_textfsm=True)
structured_result = clock_results.result
print(structured_result)
#function above is using use_textfsm=True argument to output the data from "show clock"
# and present it as structured data. Note you need to use the .result atribute to parse the data
results = nr.run(task=test_this)