Blame SOURCES/0002-Implement-restart_if-for-RedHat-OS.patch

41c999
From 0a9c628d9edd67af7b6f20d034be85c1c552a512 Mon Sep 17 00:00:00 2001
41c999
From: Miroslav Rezanina <mrezanin@redhat.com>
41c999
Date: Tue, 24 May 2022 04:10:46 -0400
41c999
Subject: Implement restart_if for RedHat OS
41c999
41c999
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
41c999
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
41c999
---
41c999
 azurelinuxagent/common/osutil/redhat.py | 18 ++++++++++++++++++
41c999
 1 file changed, 18 insertions(+)
41c999
41c999
diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py
41c999
index 9759d113..a02647cd 100644
41c999
--- a/azurelinuxagent/common/osutil/redhat.py
41c999
+++ b/azurelinuxagent/common/osutil/redhat.py
41c999
@@ -142,3 +142,21 @@ class RedhatOSUtil(Redhat6xOSUtil):
41c999
             endpoint = self.get_endpoint_from_leases_path('/var/lib/NetworkManager/dhclient-*.lease')
41c999
 
41c999
         return endpoint
41c999
+
41c999
+    def restart_if(self, ifname, retries=3, wait=5):
41c999
+        """
41c999
+        Restart an interface by bouncing the link.
41c999
+        """
41c999
+        retry_limit=retries+1
41c999
+        for attempt in range(1, retry_limit):
41c999
+            try:
41c999
+                shellutil.run_command(["ip", "link", "set", ifname, "down"])
41c999
+                shellutil.run_command(["ip", "link", "set", ifname, "up"])
41c999
+
41c999
+            except shellutil.CommandError as cmd_err:
41c999
+                logger.warn("failed to restart {0}: return code {1}".format(ifname, cmd_err.returncode))
41c999
+                if attempt < retry_limit:
41c999
+                    logger.info("retrying in {0} seconds".format(wait))
41c999
+                    time.sleep(wait)
41c999
+                else:
41c999
+                    logger.warn("exceeded restart retries")
41c999
-- 
41c999
2.31.1
41c999