2023-01-09 13:52:13 +01:00
|
|
|
From 995f67741e591b60fcecff87d4d97099ca82bafc Mon Sep 17 00:00:00 2001
|
2022-01-27 16:38:33 +01:00
|
|
|
From: Alexander Graul <agraul@suse.com>
|
|
|
|
Date: Tue, 18 Jan 2022 17:12:04 +0100
|
2019-05-20 14:43:15 +02:00
|
|
|
Subject: [PATCH] Switch firewalld state to use change_interface
|
|
|
|
|
|
|
|
firewalld.present state allows to bind interface to given zone.
|
|
|
|
However if the interface is already bound to some other zone, call-
|
|
|
|
ing `add_interface` will not change rebind the interface but report
|
|
|
|
error.
|
|
|
|
Option `change_interface` however can rebind the interface from one
|
|
|
|
zone to another.
|
|
|
|
|
|
|
|
This PR adds `firewalld.change_interface` call to firewalld module
|
|
|
|
and updates `firewalld.present` state to use this call.
|
|
|
|
---
|
2022-01-27 16:38:33 +01:00
|
|
|
salt/modules/firewalld.py | 23 +++++++++++++++++++++++
|
|
|
|
salt/states/firewalld.py | 4 +++-
|
|
|
|
2 files changed, 26 insertions(+), 1 deletion(-)
|
2019-05-20 14:43:15 +02:00
|
|
|
|
|
|
|
diff --git a/salt/modules/firewalld.py b/salt/modules/firewalld.py
|
2022-01-27 16:38:33 +01:00
|
|
|
index 135713d851..70bc738240 100644
|
2019-05-20 14:43:15 +02:00
|
|
|
--- a/salt/modules/firewalld.py
|
|
|
|
+++ b/salt/modules/firewalld.py
|
2022-01-27 16:38:33 +01:00
|
|
|
@@ -918,6 +918,29 @@ def remove_interface(zone, interface, permanent=True):
|
2021-01-08 13:41:50 +01:00
|
|
|
return __firewall_cmd(cmd)
|
|
|
|
|
|
|
|
|
2019-05-20 14:43:15 +02:00
|
|
|
+def change_interface(zone, interface, permanent=True):
|
2021-01-08 13:41:50 +01:00
|
|
|
+ """
|
2019-05-20 14:43:15 +02:00
|
|
|
+ Change zone the interface bound to
|
|
|
|
+
|
|
|
|
+ .. versionadded:: 2019.?.?
|
|
|
|
+
|
|
|
|
+ CLI Example:
|
|
|
|
+
|
|
|
|
+ .. code-block:: bash
|
|
|
|
+
|
|
|
|
+ salt '*' firewalld.change_interface zone eth0
|
2021-01-08 13:41:50 +01:00
|
|
|
+ """
|
2019-05-20 14:43:15 +02:00
|
|
|
+ if interface in get_interfaces(zone, permanent):
|
2021-01-08 13:41:50 +01:00
|
|
|
+ log.info("Interface is already bound to zone.")
|
2019-05-20 14:43:15 +02:00
|
|
|
+
|
2021-01-08 13:41:50 +01:00
|
|
|
+ cmd = "--zone={} --change-interface={}".format(zone, interface)
|
2022-01-27 16:38:33 +01:00
|
|
|
+
|
|
|
|
+ if permanent:
|
|
|
|
+ cmd += " --permanent"
|
|
|
|
+
|
|
|
|
+ return __firewall_cmd(cmd)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
def get_sources(zone, permanent=True):
|
2021-01-08 13:41:50 +01:00
|
|
|
"""
|
2022-01-27 16:38:33 +01:00
|
|
|
List sources bound to a zone
|
2019-05-20 14:43:15 +02:00
|
|
|
diff --git a/salt/states/firewalld.py b/salt/states/firewalld.py
|
2022-01-27 16:38:33 +01:00
|
|
|
index cc6eaba5c3..534b9dd62d 100644
|
2019-05-20 14:43:15 +02:00
|
|
|
--- a/salt/states/firewalld.py
|
|
|
|
+++ b/salt/states/firewalld.py
|
2022-01-27 16:38:33 +01:00
|
|
|
@@ -691,7 +691,9 @@ def _present(
|
2019-05-20 14:43:15 +02:00
|
|
|
for interface in new_interfaces:
|
2021-01-08 13:41:50 +01:00
|
|
|
if not __opts__["test"]:
|
|
|
|
try:
|
|
|
|
- __salt__["firewalld.add_interface"](name, interface, permanent=True)
|
|
|
|
+ __salt__["firewalld.change_interface"](
|
|
|
|
+ name, interface, permanent=True
|
|
|
|
+ )
|
|
|
|
except CommandExecutionError as err:
|
2022-01-27 16:38:33 +01:00
|
|
|
ret["comment"] = "Error: {}".format(err)
|
2021-01-08 13:41:50 +01:00
|
|
|
return ret
|
2019-05-20 14:43:15 +02:00
|
|
|
--
|
2023-01-09 13:52:13 +01:00
|
|
|
2.37.3
|
2019-05-20 14:43:15 +02:00
|
|
|
|
|
|
|
|