Fix_facts (#50597)
This commit is contained in:
parent
063c2f9d59
commit
6c47594388
1 changed files with 43 additions and 18 deletions
|
@ -151,9 +151,20 @@ class Default(FactsBase):
|
||||||
self.facts['hostname'] = self.parse_hostname(hdata)
|
self.facts['hostname'] = self.parse_hostname(hdata)
|
||||||
|
|
||||||
def parse_version(self, data):
|
def parse_version(self, data):
|
||||||
|
facts = dict()
|
||||||
match = re.search(r'HW Version(.+)\s(\d+)', data)
|
match = re.search(r'HW Version(.+)\s(\d+)', data)
|
||||||
if match:
|
temp, temp_next = data.split('---- ----------- ----------- -------------- --------------')
|
||||||
return match.group(2)
|
for en in temp_next.splitlines():
|
||||||
|
if en == '':
|
||||||
|
continue
|
||||||
|
match_image = re.search(r'^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)', en)
|
||||||
|
version = match_image.group(4)
|
||||||
|
facts["Version"] = list()
|
||||||
|
fact = dict()
|
||||||
|
fact['HW Version'] = match.group(2)
|
||||||
|
fact['SW Version'] = match_image.group(4)
|
||||||
|
facts["Version"].append(fact)
|
||||||
|
return facts
|
||||||
|
|
||||||
def parse_hostname(self, data):
|
def parse_hostname(self, data):
|
||||||
match = re.search(r'\S+\s(\S+)', data, re.M)
|
match = re.search(r'\S+\s(\S+)', data, re.M)
|
||||||
|
@ -207,7 +218,8 @@ class Interfaces(FactsBase):
|
||||||
'show interfaces transceiver properties',
|
'show interfaces transceiver properties',
|
||||||
'show ip int',
|
'show ip int',
|
||||||
'show lldp',
|
'show lldp',
|
||||||
'show lldp remote-device all'
|
'show lldp remote-device all',
|
||||||
|
'show version'
|
||||||
]
|
]
|
||||||
|
|
||||||
def populate(self):
|
def populate(self):
|
||||||
|
@ -218,28 +230,41 @@ class Interfaces(FactsBase):
|
||||||
desc = self.responses[1]
|
desc = self.responses[1]
|
||||||
properties = self.responses[2]
|
properties = self.responses[2]
|
||||||
vlan = self.responses[3]
|
vlan = self.responses[3]
|
||||||
vlan_info = self.parse_vlan(vlan)
|
version_info = self.responses[6]
|
||||||
|
vlan_info = self.parse_vlan(vlan, version_info)
|
||||||
self.facts['interfaces'] = self.populate_interfaces(interfaces, desc, properties)
|
self.facts['interfaces'] = self.populate_interfaces(interfaces, desc, properties)
|
||||||
self.facts['interfaces'].update(vlan_info)
|
self.facts['interfaces'].update(vlan_info)
|
||||||
if 'LLDP is not enabled' not in self.responses[4]:
|
if 'LLDP is not enabled' not in self.responses[4]:
|
||||||
neighbors = self.responses[5]
|
neighbors = self.responses[5]
|
||||||
self.facts['neighbors'] = self.parse_neighbors(neighbors)
|
self.facts['neighbors'] = self.parse_neighbors(neighbors)
|
||||||
|
|
||||||
def parse_vlan(self, vlan):
|
def parse_vlan(self, vlan, version_info):
|
||||||
facts = dict()
|
facts = dict()
|
||||||
vlan_info, vlan_info_next = vlan.split('---------- ----- --------------- --------------- -------')
|
if "N11" in version_info:
|
||||||
for en in vlan_info_next.splitlines():
|
match = re.search(r'IP Address(.+)\s([0-9.]*)\n', vlan)
|
||||||
if en == '':
|
mask = re.search(r'Subnet Mask(.+)\s([0-9.]*)\n', vlan)
|
||||||
continue
|
vlan_id_match = re.search(r'Management VLAN ID(.+)\s(\d+)', vlan)
|
||||||
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
|
vlan_id = "Vl" + vlan_id_match.group(2)
|
||||||
intf = match.group(1)
|
if vlan_id not in facts:
|
||||||
if intf not in facts:
|
facts[vlan_id] = list()
|
||||||
facts[intf] = list()
|
|
||||||
fact = dict()
|
fact = dict()
|
||||||
matc = re.search(r'^([\w+\s\d]*)\s+(\S+)\s+(\S+)', en)
|
fact['address'] = match.group(2)
|
||||||
fact['address'] = matc.group(2)
|
fact['masklen'] = mask.group(2)
|
||||||
fact['masklen'] = matc.group(3)
|
facts[vlan_id].append(fact)
|
||||||
facts[intf].append(fact)
|
else:
|
||||||
|
vlan_info, vlan_info_next = vlan.split('---------- ----- --------------- --------------- -------')
|
||||||
|
for en in vlan_info_next.splitlines():
|
||||||
|
if en == '':
|
||||||
|
continue
|
||||||
|
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
|
||||||
|
intf = match.group(1)
|
||||||
|
if intf not in facts:
|
||||||
|
facts[intf] = list()
|
||||||
|
fact = dict()
|
||||||
|
matc = re.search(r'^([\w+\s\d]*)\s+(\S+)\s+(\S+)', en)
|
||||||
|
fact['address'] = matc.group(2)
|
||||||
|
fact['masklen'] = matc.group(3)
|
||||||
|
facts[intf].append(fact)
|
||||||
return facts
|
return facts
|
||||||
|
|
||||||
def populate_interfaces(self, interfaces, desc, properties):
|
def populate_interfaces(self, interfaces, desc, properties):
|
||||||
|
@ -306,7 +331,7 @@ class Interfaces(FactsBase):
|
||||||
return match.group(2)
|
return match.group(2)
|
||||||
|
|
||||||
def parse_macaddress(self, data):
|
def parse_macaddress(self, data):
|
||||||
match = re.search(r'Burned MAC Address(.+)\s([A-Z0-9.]*)\n', data)
|
match = re.search(r'Burned In MAC Address(.+)\s([A-Z0-9.]*)\n', data)
|
||||||
if match:
|
if match:
|
||||||
return match.group(2)
|
return match.group(2)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue