From 2763d3118ae2db59ae70cb59da6a58bfb3f89a77 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Mon, 18 Dec 2023 19:18:07 -0700 Subject: [PATCH] [pfsense_interface] Run interface_bring_down() in _pre_command() when removing interface --- plugins/module_utils/interface.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/interface.py b/plugins/module_utils/interface.py index d7fa97a2..f2bfb61a 100644 --- a/plugins/module_utils/interface.py +++ b/plugins/module_utils/interface.py @@ -64,6 +64,7 @@ def __init__(self, module, pfsense=None): self.root_elt = self.pfsense.interfaces self.setup_interface_cmds = "" + self.setup_interface_pre_cmds = "" ############################## # params processing @@ -324,7 +325,7 @@ def _pre_remove_target_elt(self): self._remove_all_separators(self.target_elt.tag) self._remove_all_rules(self.target_elt.tag) - self.setup_interface_cmds += "interface_bring_down('{0}');\n".format(self.target_elt.tag) + self.setup_interface_pre_cmds += "interface_bring_down('{0}');\n".format(self.target_elt.tag) def _remove_all_rules(self, interface): """ delete all interface rules """ @@ -462,6 +463,16 @@ def _get_media_mode(self, interface): '}\n' 'echo json_encode($mediaopts_list);') + def get_pre_update_cmds(self): + """ build and return php commands to setup interfaces before changing config """ + cmd = 'require_once("filter.inc");\n' + cmd += 'require_once("interfaces.inc");\n' + + if self.setup_interface_pre_cmds != "": + cmd += self.setup_interface_pre_cmds + + return cmd + def get_update_cmds(self): """ build and return php commands to setup interfaces """ cmd = 'require_once("filter.inc");\n' @@ -482,6 +493,10 @@ def get_update_cmds(self): cmd += "if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) clear_subsystem_dirty('staticroutes');" return cmd + def _pre_update(self): + """ tasks to run before making config changes """ + return self.pfsense.phpshell(self.get_pre_update_cmds()) + def _update(self): """ make the target pfsense reload interfaces """ return self.pfsense.phpshell(self.get_update_cmds())