From 1df778917ef7b230a19d279c9e4c8628277d2f54 Mon Sep 17 00:00:00 2001 From: Dale Sedivec Date: Thu, 7 Dec 2017 14:08:13 -0600 Subject: [PATCH] Add firewalld "zone" variable for connections --- README.md | 6 ++++++ library/network_connections.py | 7 +++++++ library/test_network_connections.py | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/README.md b/README.md index f73f6e6..9d66088 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,12 @@ interface. In case of a missing `interface_name`, the profile name `name` is use Note the destinction between the profile name `name` and the device name `interface_name`, which may or may not be the same. +### `zone` + +Sets the firewalld zone for the interface. + +Slaves to bridge/bond/team devices cannot specify a zone. + ### `state: up` #### Example diff --git a/library/network_connections.py b/library/network_connections.py index 648b8f3..4fcec85 100755 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -802,6 +802,7 @@ class ArgValidator_DictConnection(ArgValidatorDict): ArgValidatorStr ('interface_name'), ArgValidatorMac ('mac'), ArgValidatorNum ('mtu', val_min = 0, val_max = 0xFFFFFFFF, default_value = None), + ArgValidatorStr ('zone'), ArgValidatorBool('check_iface_exists', default_value = True), ArgValidatorStr ('parent'), ArgValidatorNum ('vlan_id', val_min = 0, val_max = 4094, default_value = None), @@ -1192,6 +1193,9 @@ class IfcfgUtil: route4_file = content_current['route'] route6_file = content_current['route6'] else: + if connection['zone']: + ifcfg['ZONE'] = connection['zone'] + addrs4 = list([a for a in ip['address'] if a['family'] == socket.AF_INET]) addrs6 = list([a for a in ip['address'] if a['family'] == socket.AF_INET6]) @@ -1555,6 +1559,9 @@ class NMUtil: s_con.set_property(NM.SETTING_CONNECTION_SLAVE_TYPE, connection['slave_type']) s_con.set_property(NM.SETTING_CONNECTION_MASTER, ArgUtil.connection_find_master_uuid(connection['master'], connections, idx)) else: + if connection['zone']: + s_con.set_property(NM.SETTING_CONNECTION_ZONE, connection['zone']) + ip = connection['ip'] s_ip4 = self.connection_ensure_setting(con, NM.SettingIP4Config) diff --git a/library/test_network_connections.py b/library/test_network_connections.py index 740e747..9587d26 100755 --- a/library/test_network_connections.py +++ b/library/test_network_connections.py @@ -251,6 +251,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'master': None, 'vlan_id': None, 'ignore_errors': None, @@ -300,6 +301,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'master': None, 'vlan_id': None, 'ignore_errors': None, @@ -370,6 +372,7 @@ class TestValidator(unittest.TestCase): 'check_iface_exists': True, 'force_state_change': None, 'mac': '52:54:00:44:9f:ba', + 'zone': None, 'master': None, 'vlan_id': None, 'ignore_errors': None, @@ -433,6 +436,7 @@ class TestValidator(unittest.TestCase): 'check_iface_exists': True, 'force_state_change': None, 'mac': '52:54:00:44:9f:ba', + 'zone': None, 'master': None, 'vlan_id': None, 'ignore_errors': None, @@ -483,6 +487,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'check_iface_exists': True, 'force_state_change': None, 'state': 'up', @@ -558,6 +563,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'check_iface_exists': True, 'force_state_change': None, 'state': 'up', @@ -592,6 +598,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'check_iface_exists': True, 'force_state_change': None, 'state': 'up', @@ -650,6 +657,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'check_iface_exists': True, 'force_state_change': None, 'state': 'up', @@ -700,6 +708,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'check_iface_exists': True, 'force_state_change': None, 'state': 'up', @@ -755,6 +764,7 @@ class TestValidator(unittest.TestCase): }, 'mac': 'aa:bb:cc:dd:ee:ff', 'mtu': None, + 'zone': None, 'master': None, 'check_iface_exists': True, 'name': '5', @@ -802,6 +812,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'master': None, 'vlan_id': None, 'ignore_errors': None, @@ -847,6 +858,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'master': None, 'vlan_id': None, 'ignore_errors': None, @@ -909,6 +921,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': None, 'master': None, 'vlan_id': None, 'ignore_errors': None, @@ -1007,6 +1020,7 @@ class TestValidator(unittest.TestCase): }, 'mac': None, 'mtu': None, + 'zone': 'external', 'master': None, 'vlan_id': None, 'ignore_errors': None, @@ -1023,6 +1037,7 @@ class TestValidator(unittest.TestCase): { 'name': 'e556', 'state': 'up', 'type': 'ethernet', + 'zone': 'external', 'ip': { 'dns_search': [ 'aa', 'bb' ], 'route_append_only': True, @@ -1103,6 +1118,7 @@ class TestValidator(unittest.TestCase): 'NM_CONTROLLED': 'no', 'ONBOOT': 'yes', 'TYPE': 'Ethernet', + 'ZONE': 'external', }, 'keys': None, 'route': '192.168.40.0/24 metric 545\n192.168.46.0/30\n192.168.45.0/24 metric 545\n',