handle more lldp formats

This commit is contained in:
Solvik Blum 2019-08-23 17:51:49 +02:00
parent 6b5715c7c6
commit d5a2a3047f
No known key found for this signature in database
GPG key ID: CC12B3DC262B6C47

View file

@ -9,6 +9,8 @@ class LLDP():
def parse(self): def parse(self):
output_dict = {} output_dict = {}
for entry in self.output.splitlines(): for entry in self.output.splitlines():
if '=' not in entry:
continue
path, value = entry.strip().split("=", 1) path, value = entry.strip().split("=", 1)
path = path.split(".") path = path.split(".")
path_components, final = path[:-1], path[-1] path_components, final = path[:-1], path[-1]
@ -37,6 +39,10 @@ class LLDP():
if self.data['lldp'].get(interface) is None: if self.data['lldp'].get(interface) is None:
return None return None
if self.data['lldp'][interface].get('vlan'): lldp = self.data['lldp'][interface]
return int(self.data['lldp'][interface]['vlan'].replace('vlan-', '')) if lldp.get('vlan'):
if lldp['vlan'].get('vlan-id'):
return int(lldp['vlan'].get('vlan-id'))
elif type(lldp['vlan']) is str:
return int(lldp['vlan'].replace('vlan-', ''))
return None return None