Skip to content

Commit

Permalink
[pfsense_interface] Run interface_bring_down() in _pre_command() when…
Browse files Browse the repository at this point in the history
… removing interface
  • Loading branch information
opoplawski committed Dec 19, 2023
1 parent 3ab7e3c commit 2763d31
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion plugins/module_utils/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 """
Expand Down Expand Up @@ -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'
Expand All @@ -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())
Expand Down

0 comments on commit 2763d31

Please sign in to comment.