From e2fef7beedaf2b7ab8128bb851cb20a0c2951fb8 Mon Sep 17 00:00:00 2001 From: chifu1234 Date: Wed, 15 Nov 2017 15:38:19 +0100 Subject: [PATCH] nxos_facts: cdp support (#31202) * nxos_facts get CPD neighbor * nxos_fact: cdp support * remove blank spaces * add ansible_net_neighbors cdp informations --- .../modules/network/nxos/nxos_facts.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/network/nxos/nxos_facts.py b/lib/ansible/modules/network/nxos/nxos_facts.py index f8ce57b96e..ec12ce3d9b 100644 --- a/lib/ansible/modules/network/nxos/nxos_facts.py +++ b/lib/ansible/modules/network/nxos/nxos_facts.py @@ -128,7 +128,7 @@ ansible_net_interfaces: returned: when interfaces is configured type: dict ansible_net_neighbors: - description: The list of LLDP neighbors from the remote device + description: The list of LLDP/CDP neighbors from the remote device returned: when interfaces is configured type: dict @@ -297,6 +297,10 @@ class Interfaces(FactsBase): if data: self.facts['neighbors'] = self.populate_neighbors(data) + data = self.run('show cdp neighbors detail', 'json') + if data: + self.facts['neighbors'] = self.populate_neighbors_cdp(data) + def populate_interfaces(self, data): interfaces = dict() for item in data['TABLE_interface']['ROW_interface']: @@ -347,6 +351,23 @@ class Interfaces(FactsBase): return objects + def populate_neighbors_cdp(self, data): + objects = dict() + data = data['TABLE_cdp_neighbor_detail_info']['ROW_cdp_neighbor_detail_info'] + + if isinstance(data, dict): + data = [data] + + for item in data: + local_intf = item['intf_id'] + objects[local_intf] = list() + nbor = dict() + nbor['port'] = item['port_id'] + nbor['sysname'] = item['device_id'] + objects[local_intf].append(nbor) + + return objects + def parse_ipv6_interfaces(self, data): try: data = data['TABLE_intf']