summaryrefslogtreecommitdiff
path: root/plugins/module_utils/network
diff options
context:
space:
mode:
authoromnom62 <75066712+omnom62@users.noreply.github.com>2025-11-27 06:00:30 +1000
committerGitHub <noreply@github.com>2025-11-26 20:00:30 +0000
commit85e132415cd7917c677d27b9085d17f50bc3da2e (patch)
tree0982a65bff1a6e74d5c8929349a92414b6008f1b /plugins/module_utils/network
parentcba33a3b88f58881d7989a22292b25901cb3242c (diff)
downloadvyos.vyos-85e132415cd7917c677d27b9085d17f50bc3da2e.tar.gz
vyos.vyos-85e132415cd7917c677d27b9085d17f50bc3da2e.zip
T6823: correctly set the IPv6 autoconf option (#433)
* T6823 init fix * slaac and integration tests * reaplced integration test * WIP integration tests * changelog and tweaks * rendered, gathered, parsed, integration tests for SLAAC * l3_interfaces gathered, emty, deleted * deleted integration test * vif processing * vif tests * vir related integration test cases * ignore ansible-bad-import-from * ansible-bad-import-from ingore * ignore ansible-bad-import-from for all * test ansible-bad-import-from skip * ingore file * Fix bugs with configuration remove * Delete testcase fixed * SLAAC integration tests * Sanity check fixes * remove_config formatted * l3 slaac eth0 removed from SIT * Remove ignore 2.20 * ignore2.20 recovered * Remove residue
Diffstat (limited to 'plugins/module_utils/network')
-rw-r--r--plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py101
1 files changed, 68 insertions, 33 deletions
diff --git a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
index ee709e2a..a23494cd 100644
--- a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
@@ -79,7 +79,7 @@ class L3_interfaces(ConfigBase):
commands = list()
if self.state in self.ACTION_STATES:
- existing_l3_interfaces_facts = self.get_l3_interfaces_facts()
+ existing_l3_interfaces_facts = self.mutate_autoconfig(self.get_l3_interfaces_facts())
else:
existing_l3_interfaces_facts = []
@@ -95,16 +95,19 @@ class L3_interfaces(ConfigBase):
result["commands"] = commands
if self.state in self.ACTION_STATES or self.state == "gathered":
- changed_l3_interfaces_facts = self.get_l3_interfaces_facts()
+ changed_l3_interfaces_facts = self.mutate_autoconfig(self.get_l3_interfaces_facts())
elif self.state == "rendered":
result["rendered"] = commands
elif self.state == "parsed":
running_config = self._module.params["running_config"]
+
if not running_config:
self._module.fail_json(
msg="value of running_config parameter must not be empty for state parsed",
)
- result["parsed"] = self.get_l3_interfaces_facts(data=running_config)
+ result["parsed"] = self.mutate_autoconfig(
+ self.get_l3_interfaces_facts(data=running_config),
+ )
else:
changed_l3_interfaces_facts = []
@@ -128,6 +131,7 @@ class L3_interfaces(ConfigBase):
"""
want = self._module.params["config"]
have = existing_l3_interfaces_facts
+
resp = self.set_state(want, have)
return to_list(resp)
@@ -173,6 +177,7 @@ class L3_interfaces(ConfigBase):
elif state == "replaced":
commands.extend(self._state_replaced(item, obj_in_have))
+ commands = [command.replace("auto-config", "autoconf") for command in commands]
return commands
def _state_replaced(self, want, have):
@@ -246,7 +251,6 @@ class L3_interfaces(ConfigBase):
vif=want_vif["vlan_id"],
),
)
-
return commands
def _state_deleted(self, want, have):
@@ -260,51 +264,73 @@ class L3_interfaces(ConfigBase):
want_copy = deepcopy(remove_empties(want))
have_copy = deepcopy(have)
- want_vifs = want_copy.pop("vifs", [])
- have_vifs = have_copy.pop("vifs", [])
-
- for update in self._get_updates(have_copy, want_copy):
- for key, value in update.items():
+ if have_copy is not None:
+ if all(v in (None, {}, []) for k, v in want_copy.items() if k != "name"):
commands.append(
self._compute_commands(
- key=key,
- value=value,
+ key=None,
+ value=None,
interface=want_copy["name"],
remove=True,
),
)
-
- if have_vifs:
- for have_vif in have_vifs:
- want_vif = search_obj_in_list(have_vif["vlan_id"], want_vifs, key="vlan_id")
- if not want_vif:
- want_vif = {"vlan_id": have_vif["vlan_id"]}
-
- for update in self._get_updates(have_vif, want_vif):
- for key, value in update.items():
- commands.append(
- self._compute_commands(
- key=key,
- interface=want_copy["name"],
- value=value,
- vif=want_vif["vlan_id"],
- remove=True,
- ),
- )
+ return commands
+
+ want_vifs = want_copy.pop("vifs", [])
+ have_vifs = have_copy.pop("vifs", [])
+
+ if have_vifs:
+ for have_vif in have_vifs:
+ want_vif = search_obj_in_list(have_vif["vlan_id"], want_vifs, key="vlan_id")
+ if not want_vif:
+ want_vif = {"vlan_id": have_vif["vlan_id"]}
+
+ for update in self._get_updates(have_vif, want_vif):
+ for key, value in update.items():
+ commands.append(
+ self._compute_commands(
+ key=key,
+ interface=want_copy["name"],
+ value=value,
+ vif=want_vif["vlan_id"],
+ remove=True,
+ ),
+ )
+
+ for update in self._get_updates(have_copy, want_copy):
+ for key, value in update.items():
+ commands.append(
+ self._compute_commands(
+ key=key,
+ value=value,
+ interface=want_copy["name"],
+ remove=True,
+ ),
+ )
return commands
def _compute_commands(self, interface, key, vif=None, value=None, remove=False):
- intf_context = "interfaces {0} {1}".format(get_interface_type(interface), interface)
+ if value == "auto-config" and vif is None:
+ intf_context = "interfaces {0} {1} ipv6".format(
+ get_interface_type(interface),
+ interface,
+ )
+ else:
+ intf_context = "interfaces {0} {1}".format(get_interface_type(interface), interface)
+
set_cmd = "set {0}".format(intf_context)
del_cmd = "delete {0}".format(intf_context)
if vif:
- set_cmd = set_cmd + (" vif {0}".format(vif))
- del_cmd = del_cmd + (" vif {0}".format(vif))
+ suffix = " ipv6" if value == "auto-config" else ""
+ set_cmd += f" vif {vif}{suffix}"
+ del_cmd += f" vif {vif}{suffix}"
- if remove:
+ if remove and key and value:
command = "{0} {1} '{2}'".format(del_cmd, key, value)
+ elif remove and not (key and value):
+ command = "{0}".format(del_cmd)
else:
command = "{0} {1} '{2}'".format(set_cmd, key, value)
@@ -317,3 +343,12 @@ class L3_interfaces(ConfigBase):
updates.extend(diff_list_of_dicts(want.get("ipv6", []), have.get("ipv6", [])))
return updates
+
+ def mutate_autoconfig(self, obj):
+ if isinstance(obj, dict):
+ return dict(map(lambda kv: (kv[0], self.mutate_autoconfig(kv[1])), obj.items()))
+ if isinstance(obj, list):
+ return list(map(self.mutate_autoconfig, obj))
+ if isinstance(obj, str):
+ return obj.replace("autoconf", "auto-config")
+ return obj