Fix LLDP to use json (#48318)
This commit is contained in:
parent
92b2d01a8a
commit
e51964e7a6
1 changed files with 24 additions and 2 deletions
|
@ -421,9 +421,12 @@ class Interfaces(FactsBase):
|
||||||
interfaces = self.parse_interfaces(data)
|
interfaces = self.parse_interfaces(data)
|
||||||
self.populate_ipv6_interfaces(interfaces)
|
self.populate_ipv6_interfaces(interfaces)
|
||||||
|
|
||||||
data = self.run('show lldp neighbors')
|
data = self.run('show lldp neighbors', output='json')
|
||||||
if data:
|
if data:
|
||||||
self.facts['neighbors'].update(self.populate_neighbors(data))
|
if isinstance(data, dict):
|
||||||
|
self.facts['neighbors'].update(self.populate_structured_neighbors_lldp(data))
|
||||||
|
else:
|
||||||
|
self.facts['neighbors'].update(self.populate_neighbors(data))
|
||||||
|
|
||||||
data = self.run('show cdp neighbors detail', output='json')
|
data = self.run('show cdp neighbors detail', output='json')
|
||||||
if data:
|
if data:
|
||||||
|
@ -432,6 +435,8 @@ class Interfaces(FactsBase):
|
||||||
else:
|
else:
|
||||||
self.facts['neighbors'].update(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):
|
def populate_structured_interfaces(self, data):
|
||||||
interfaces = dict()
|
interfaces = dict()
|
||||||
for item in data['TABLE_interface']['ROW_interface']:
|
for item in data['TABLE_interface']['ROW_interface']:
|
||||||
|
@ -475,6 +480,23 @@ class Interfaces(FactsBase):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return ""
|
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):
|
def populate_structured_neighbors_cdp(self, data):
|
||||||
objects = dict()
|
objects = dict()
|
||||||
data = data['TABLE_cdp_neighbor_detail_info']['ROW_cdp_neighbor_detail_info']
|
data = data['TABLE_cdp_neighbor_detail_info']['ROW_cdp_neighbor_detail_info']
|
||||||
|
|
Loading…
Reference in a new issue