From ee4259399811d11fbea008ce9fc0a1ea93e5d266 Mon Sep 17 00:00:00 2001 From: Shannon Byrnes Date: Sun, 17 Mar 2024 18:12:11 -0700 Subject: [PATCH] wip --- ...ko_update_description_to_lldp_neighbors.py | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/lab-2/3_netmiko_update_description_to_lldp_neighbors.py b/lab-2/3_netmiko_update_description_to_lldp_neighbors.py index 8bb014a..079dcf1 100644 --- a/lab-2/3_netmiko_update_description_to_lldp_neighbors.py +++ b/lab-2/3_netmiko_update_description_to_lldp_neighbors.py @@ -21,5 +21,44 @@ # Send a command to the router, and get back the output "dictionaried" by textfsm. textfsm_output = connection.send_command(command_to_run, use_textfsm=True) - # We know that the output looks like this: - # OUTPUT HERE + # We know that textfsm_output looks something like this for a host: + # [ + # { + # "local_interface": "GigabitEthernet0/0/0/0", + # "chassis_id": "0006.283d.5b1f", + # "neighbor_port_description": "-> CISCO3", + # "neighbor_port_id": "GigabitEthernet0/0/0/0", + # "neighbor": "cisco1", + # "system_description": "7.11.1, XRd Control Plane", + # "capabilities": "R", + # "management_ip": "172.17.1.18", + # "management_ipv6": "2001:db8:16:1::2", + # "mac_address": "aa:c1:ab:40:84:35" + # }, + # { + # "local_interface": "GigabitEthernet0/0/0/1", + # "chassis_id": "0012.003b.94fe", + # "neighbor_port_description": "-> CISCO3", + # "neighbor_port_id": "GigabitEthernet0/0/0/0", + # "neighbor": "cisco2", + # "system_description": "7.11.1, XRd Control Plane", + # "capabilities": "R", + # "management_ip": "172.17.1.20", + # "management_ipv6": "2001:db8:16:1::3", + # "mac_address": "aa:c1:ab:0f:7e:46" + # } + # ] + + for lldp_neighbor in textfsm_output: + my_interface = lldp_neighbor["local_interface"] + neighbor_interface = lldp_neighbor["neighbor_port_id"] + neighbor_name = lldp_neighbor["neighbor"] + + configuration = [ + f"int {my_interface}", + f"description ->{neighbor_name}, {neighbor_interface}" + ] + + output = connection.send_config_set(configuration) + print(output) + print(connection.send_command(f"show run int {my_interface}"))