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

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