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

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