From 4caef8413e4c2cc93fdc3958fbfd6476436afd48 Mon Sep 17 00:00:00 2001 From: Steve Dodd Date: Mon, 12 Nov 2018 00:01:27 -0700 Subject: [PATCH] Fix LLDP to use json (#48318) (cherry picked from commit e51964e7a6552bab3cfb7c2dfe07dd33512f477a) --- .../modules/network/nxos/nxos_facts.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_facts.py b/lib/ansible/modules/network/nxos/nxos_facts.py index 5dbae8a2030..0e8d5357207 100644 --- a/lib/ansible/modules/network/nxos/nxos_facts.py +++ b/lib/ansible/modules/network/nxos/nxos_facts.py @@ -398,14 +398,16 @@ class Interfaces(FactsBase): data = self.run('show lldp neighbors') if data: - self.facts['neighbors'] = self.populate_neighbors(data) + self.facts['neighbors'].update(self.populate_neighbors(data)) data = self.run('show cdp neighbors detail', output='json') if data: if isinstance(data, dict): - self.facts['neighbors'] = self.populate_structured_neighbors_cdp(data) + self.facts['neighbors'].update(self.populate_structured_neighbors_cdp(data)) else: - self.facts['neighbors'] = self.populate_neighbors_cdp(data) + self.facts['neighbors'].update(self.populate_neighbors_cdp(data)) + + self.facts['neighbors'].pop(None, None) # Remove null key def populate_structured_interfaces(self, data): interfaces = dict() @@ -450,6 +452,23 @@ class Interfaces(FactsBase): except TypeError: return "" + def populate_structured_neighbors_lldp(self, data): + objects = dict() + data = data['TABLE_nbor']['ROW_nbor'] + + if isinstance(data, dict): + data = [data] + + for item in data: + local_intf = item['l_port_id'] + objects[local_intf] = list() + nbor = dict() + nbor['port'] = item['port_id'] + nbor['sysname'] = item['chassis_id'] + objects[local_intf].append(nbor) + + return objects + def populate_structured_neighbors_cdp(self, data): objects = dict() data = data['TABLE_cdp_neighbor_detail_info']['ROW_cdp_neighbor_detail_info']