Blame SOURCES/rhel-system-roles-network-pr121.diff

cc4018
diff --git a/library/network_connections.py b/library/network_connections.py
cc4018
index 39e81e8..6fa5e2f 100644
cc4018
--- a/library/network_connections.py
cc4018
+++ b/library/network_connections.py
cc4018
@@ -1369,6 +1369,13 @@ class NMUtil:
cc4018
             finally:
cc4018
                 ac.handler_disconnect(ac_id)
cc4018
 
cc4018
+    def reapply(self, device, connection=None):
cc4018
+        version_id = 0
cc4018
+        flags = 0
cc4018
+        return Util.call_async_method(
cc4018
+            device, "reapply", [connection, version_id, flags]
cc4018
+        )
cc4018
+
cc4018
 
cc4018
 ###############################################################################
cc4018
 
cc4018
@@ -2088,6 +2095,9 @@ class Cmd_nm(Cmd):
cc4018
         )
cc4018
         self.connections_data_set_changed(idx)
cc4018
         if self.check_mode == CheckMode.REAL_RUN:
cc4018
+            if self._try_reapply(idx, con):
cc4018
+                return
cc4018
+
cc4018
             try:
cc4018
                 ac = self.nmutil.connection_activate(con)
cc4018
             except MyError as e:
cc4018
@@ -2102,6 +2112,33 @@ class Cmd_nm(Cmd):
cc4018
             except MyError as e:
cc4018
                 self.log_error(idx, "up connection failed while waiting: %s" % (e))
cc4018
 
cc4018
+    def _try_reapply(self, idx, con):
cc4018
+        """ Try to reapply a connection
cc4018
+
cc4018
+        If there is exactly one active connection with the same UUID activated
cc4018
+        on exactly one device, ask the device to reapply the connection.
cc4018
+
cc4018
+        :returns: `True`, when the connection was reapplied, `False` otherwise
cc4018
+        :rtype: bool
cc4018
+        """
cc4018
+        NM = Util.NM()
cc4018
+
cc4018
+        acons = list(self.nmutil.active_connection_list(connections=[con]))
cc4018
+        if len(acons) != 1:
cc4018
+            return False
cc4018
+
cc4018
+        active_connection = acons[0]
cc4018
+        if active_connection.get_state() == NM.ActiveConnectionState.ACTIVATED:
cc4018
+            devices = active_connection.get_devices()
cc4018
+            if len(devices) == 1:
cc4018
+                try:
cc4018
+                    self.nmutil.reapply(devices[0])
cc4018
+                    self.log_info(idx, "connection reapplied")
cc4018
+                    return True
cc4018
+                except MyError as error:
cc4018
+                    self.log_info(idx, "connection reapply failed: %s" % (error))
cc4018
+        return False
cc4018
+
cc4018
     def run_action_down(self, idx):
cc4018
         connection = self.connections[idx]
cc4018