From 1f30825dc5a85f25b36c9e1335cae797cf250bf4 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Thu, 4 Jan 2024 07:31:56 -0700 Subject: [PATCH] [pfsense_openvpn_server] Do not allow removal of an instance with an interface assignment --- plugins/module_utils/openvpn_server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/module_utils/openvpn_server.py b/plugins/module_utils/openvpn_server.py index 073d7dc1..cd3011aa 100644 --- a/plugins/module_utils/openvpn_server.py +++ b/plugins/module_utils/openvpn_server.py @@ -331,6 +331,11 @@ def _find_target(self): def _pre_remove_target_elt(self): """ processing before removing elt """ self.diff['before'] = self.pfsense.element_to_dict(self.target_elt) + + if len(self.pfsense.interfaces.findall("*[if='ovpns{0}']".format(self.diff['before']['vpnid']))) > 0: + self.module.fail_json(msg='Cannot delete the OpenVPN instance while the interface ovpns{0} is assigned. Remove the interface assignment first.' + .format(self.diff['before']['vpnid'])) + self.result['vpnid'] = int(self.diff['before']['vpnid']) self.command_output = self.pfsense.phpshell(OPENVPN_SERVER_PHP_COMMAND_DEL.format(idx=self.idx))