mirror of
https://github.com/ansible-collections/community.routeros.git
synced 2025-08-28 22:08:23 +02:00
Handle IP addresses configured on disappeared interfaces (#391)
* Handle IP addresses configured on disappeared interfaces * Handle IP addresses configured on disappeared interfaces Always set type property, add changelog fragment * Handle IP addresses configured on disappeared interfaces (wording) Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Claudio Luck <claudio.luck@datact.ch> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
fb070e4ac6
commit
f6aeae1abd
2 changed files with 17 additions and 3 deletions
12
changelogs/fragments/391-report-unknown-interfaces.yml
Normal file
12
changelogs/fragments/391-report-unknown-interfaces.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
bugfixes:
|
||||
- |
|
||||
api_facts - also report interfaces that are inferred only by reference by IP addresses.
|
||||
RouterOS's APIs have IPv4 and IPv6 addresses point at interfaces by their name, which can
|
||||
change over time and in-between API calls, such that interfaces may have been enumerated
|
||||
under another name, or not at all (for example when removed). Such interfaces are now reported
|
||||
under their new or temporary name and with a synthetic ``type`` property set to differentiate
|
||||
the more likely and positively confirmed removal case (with ``type: "ansible:unknown"``) from
|
||||
the unlikely and probably transient naming mismatch (with ``type: "ansible:mismatch"``).
|
||||
Previously, the api_facts module would have crashed with a ``KeyError`` exception
|
||||
(https://github.com/ansible-collections/community.routeros/pull/391).
|
|
@ -317,8 +317,10 @@ class Interfaces(FactsBase):
|
|||
def populate_addresses(self, data, family):
|
||||
for value in data:
|
||||
key = value['interface']
|
||||
if family not in self.facts['interfaces'][key]:
|
||||
self.facts['interfaces'][key][family] = []
|
||||
iface = self.facts['interfaces'].setdefault(key, (
|
||||
{"type": "ansible:unknown"} if key.startswith('*') else
|
||||
{"type": "ansible:mismatch"}))
|
||||
iface_addrs = iface.setdefault(family, [])
|
||||
addr, subnet = value['address'].split('/')
|
||||
subnet = subnet.strip()
|
||||
# Try to convert subnet to an integer
|
||||
|
@ -328,7 +330,7 @@ class Interfaces(FactsBase):
|
|||
pass
|
||||
ip = dict(address=addr.strip(), subnet=subnet)
|
||||
self.add_ip_address(addr.strip(), family)
|
||||
self.facts['interfaces'][key][family].append(ip)
|
||||
iface_addrs.append(ip)
|
||||
|
||||
def add_ip_address(self, address, family):
|
||||
if family == 'ipv4':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue