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