Skip to content

Commit

Permalink
fixes error parsing lldp neighbors when running nxos_facts (#23134)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2e476e6)
  • Loading branch information
privateip authored and Peter Sprygada committed Mar 30, 2017
1 parent 1b188c1 commit 7afc9ac
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/ansible/modules/network/nxos/nxos_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,18 @@ def populate_neighbors(self, data):
if data.startswith('ERROR'):
return dict()

data = data['TABLE_nbor']['ROW_nbor']
if isinstance(data, dict):
data = [data]
lines = data.split('\n')
regex = re.compile('(\S+)\s+(\S+)\s+\d+\s+\w+\s+(\S+)')

objects = dict()
for item in data:
local_intf = item['l_port_id']
if local_intf not in objects:
objects[local_intf] = list()
nbor = dict()
nbor['port'] = item['port_id']
nbor['host'] = item['chassis_id']
objects[local_intf].append(nbor)

for item in data.split('\n')[4:-1]:
match = regex.match(item)
if match:
nbor = {'host': match.group(1), 'port': match.group(3)}
if match.group(2) not in objects:
objects[match.group(2)] = []
objects[match.group(2)].append(nbor)
return objects

def parse_ipv6_interfaces(self, data):
Expand Down

0 comments on commit 7afc9ac

Please sign in to comment.