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