-
Notifications
You must be signed in to change notification settings - Fork 15
/
run_nornir.py
51 lines (40 loc) · 1.49 KB
/
run_nornir.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Example from Patrick Ogenstad at Networklore
# https://networklore.com/introducing-nornir
# https://blogs.cisco.com/developer/nornir-python-automation-framework
from nornir.core import InitNornir
from nornir.plugins.tasks.networking import napalm_get, napalm_cli
from nornir.plugins.functions.text import print_result
nornir_instance = InitNornir(dry_run=True)
myhosts = nornir_instance.inventory.hosts['pacific-as01'].to_dict()
# print(myhosts)
# result = nornir_object.run(
# napalm_get,
# getters=['get_facts'])
cli_result = nornir_instance.run(napalm_cli,commands=['show vlan', 'show ver'])
print()
print("cli keys")
print(cli_result.keys())
print(cli_result['pacific-as01'])
print("result keys")
print(cli_result['pacific-as01'][0].result.keys())
# print(cli_result['pacific-as01'][0].result['show vlan'])
# print(cli_result['pacific-as01'][0].result['show ver'])
# print(len(cli_result['pacific-as01']))
# print(dir(cli_result['pacific-as01'][0]))
# for item in cli_result:
# myhosts = nornir_instance.inventory.hosts[item].to_dict()
# print(myhosts)
# print()
# print(cli_result[item])
# # print(dir(cli_result[item]))
# for i in cli_result[item]:
# print("\ti[0] is {}".format(i[0]))
# print("++++++++++++++++")
# print(i['napalm_cli'])
# print(item)
# print(dir(item))
# print(type(item))
print("="*40)
# print_result(cli_result)
# print("="*40)
# print_result(cli_result)