-
Notifications
You must be signed in to change notification settings - Fork 13
/
cdp-map.py
24 lines (19 loc) · 943 Bytes
/
cdp-map.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
from nornir import InitNornir
from nornir.plugins.functions.text import print_result, print_title
from nornir.plugins.tasks.networking import netmiko_send_command, netmiko_send_config
nr = InitNornir(config_file="config.yaml")
def cdp_map(task):
r = task.run(task=netmiko_send_command, command_string = "show cdp neighbor", use_genie=True)
task.host["facts"] = r.result
outer = task.host["facts"]
indexer = outer['cdp']['index']
for idx in indexer:
local_intf = indexer[idx]['local_interface']
remote_port = indexer[idx]['port_id']
remote_id = indexer[idx]['device_id']
cdp_config = task.run(netmiko_send_config,name="Automating CDP Network Descriptions",config_commands=[
"interface " + str(local_intf),
"description Connected to " + str(remote_id) + " via its " + str(remote_port) + " interface"]
)
results = nr.run(task=cdp_map)
print_result(results)