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

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