mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
ios_facts: Fixed Retrieving All IPv4 Addresses on L3 Interfaces (#25462)
* Fixed Retrieving All IPv4 Addresses on L3 Interfaces The ios_facts module retrieving the interface subnet, would only get the primary IPv4 address on the interface and would not capture all the secondary IPs (ones that I would be set by "ip address x.x.x.x x.x.x.x secondary"). This was tested and confirmed to work on a Cisco 6500 with IOS 15.1(2)SY6. * Fixed whitespace and if statement issues for sanity. * Fixed spacing because sanity.
This commit is contained in:
parent
03d3c6135d
commit
a25c6b9478
1 changed files with 22 additions and 6 deletions
|
@ -248,6 +248,7 @@ class Interfaces(FactsBase):
|
||||||
|
|
||||||
COMMANDS = [
|
COMMANDS = [
|
||||||
'show interfaces',
|
'show interfaces',
|
||||||
|
'show ip interface',
|
||||||
'show ipv6 interface',
|
'show ipv6 interface',
|
||||||
'show lldp'
|
'show lldp'
|
||||||
]
|
]
|
||||||
|
@ -266,9 +267,14 @@ class Interfaces(FactsBase):
|
||||||
data = self.responses[1]
|
data = self.responses[1]
|
||||||
if data:
|
if data:
|
||||||
data = self.parse_interfaces(data)
|
data = self.parse_interfaces(data)
|
||||||
self.populate_ipv6_interfaces(data)
|
self.populate_ipv4_interfaces(data)
|
||||||
|
|
||||||
data = self.responses[2]
|
data = self.responses[2]
|
||||||
|
if data:
|
||||||
|
data = self.parse_interfaces(data)
|
||||||
|
self.populate_ipv6_interfaces(data)
|
||||||
|
|
||||||
|
data = self.responses[3]
|
||||||
if data:
|
if data:
|
||||||
neighbors = self.run(['show lldp neighbors detail'])
|
neighbors = self.run(['show lldp neighbors detail'])
|
||||||
if neighbors:
|
if neighbors:
|
||||||
|
@ -281,11 +287,6 @@ class Interfaces(FactsBase):
|
||||||
intf['description'] = self.parse_description(value)
|
intf['description'] = self.parse_description(value)
|
||||||
intf['macaddress'] = self.parse_macaddress(value)
|
intf['macaddress'] = self.parse_macaddress(value)
|
||||||
|
|
||||||
ipv4 = self.parse_ipv4(value)
|
|
||||||
intf['ipv4'] = self.parse_ipv4(value)
|
|
||||||
if ipv4:
|
|
||||||
self.add_ip_address(ipv4['address'], 'ipv4')
|
|
||||||
|
|
||||||
intf['mtu'] = self.parse_mtu(value)
|
intf['mtu'] = self.parse_mtu(value)
|
||||||
intf['bandwidth'] = self.parse_bandwidth(value)
|
intf['bandwidth'] = self.parse_bandwidth(value)
|
||||||
intf['mediatype'] = self.parse_mediatype(value)
|
intf['mediatype'] = self.parse_mediatype(value)
|
||||||
|
@ -297,6 +298,21 @@ class Interfaces(FactsBase):
|
||||||
facts[key] = intf
|
facts[key] = intf
|
||||||
return facts
|
return facts
|
||||||
|
|
||||||
|
def populate_ipv4_interfaces(self, data):
|
||||||
|
for key, value in data.items():
|
||||||
|
self.facts['interfaces'][key]['ipv4'] = list()
|
||||||
|
primary_address = addresses = []
|
||||||
|
primary_address = re.findall(r'Internet address is (.+)$', value, re.M)
|
||||||
|
addresses = re.findall(r'Secondary address (.+)$', value, re.M)
|
||||||
|
if len(primary_address) == 0:
|
||||||
|
continue
|
||||||
|
addresses.append(primary_address[0])
|
||||||
|
for address in addresses:
|
||||||
|
addr, subnet = address.split("/")
|
||||||
|
ipv4 = dict(address=addr.strip(), subnet=subnet.strip())
|
||||||
|
self.add_ip_address(addr.strip(), 'ipv4')
|
||||||
|
self.facts['interfaces'][key]['ipv4'].append(ipv4)
|
||||||
|
|
||||||
def populate_ipv6_interfaces(self, data):
|
def populate_ipv6_interfaces(self, data):
|
||||||
for key, value in iteritems(data):
|
for key, value in iteritems(data):
|
||||||
self.facts['interfaces'][key]['ipv6'] = list()
|
self.facts['interfaces'][key]['ipv6'] = list()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue