Blame SOURCES/wla-redhat-Use-NetworkManager-to-set-DHCP-hostnames-on-r.patch

1d2ea3
From f45dc73365999334e680d64c90d36f710a0c7831 Mon Sep 17 00:00:00 2001
1d2ea3
From: Mohammed Gamal <mgamal@redhat.com>
1d2ea3
Date: Fri, 29 Jul 2022 13:07:13 +0200
1d2ea3
Subject: [PATCH 1/2] redhat: Use NetworkManager to set DHCP hostnames on
1d2ea3
 recent RHEL distros
1d2ea3
1d2ea3
RH-Author: Mohamed Gamal Morsy <mmorsy@redhat.com>
1d2ea3
RH-MergeRequest: 8: redhat: Use NetworkManager to set DHCP hostnames on recent RHEL distros
1d2ea3
RH-Commit: [1/1] b83612e9d88bac7117541d7f7832f65ef268bbe3
1d2ea3
RH-Bugzilla: 2092002
1d2ea3
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
1d2ea3
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
1d2ea3
1d2ea3
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2092002
1d2ea3
1d2ea3
Recent versions of RHEL 8 and RHEL 9 started using NetworkManager to configure
1d2ea3
network intefaces instead of sysconfig files. Configurations are no longer
1d2ea3
stored in /etc/sysconfig/ifcfg-{interface}.
1d2ea3
1d2ea3
Fix this for setting DHCP hostnames in those RHEL versions.
1d2ea3
1d2ea3
Signed-off-by: Mohammed Gamal <mgamal@redhat.com>
1d2ea3
---
1d2ea3
 azurelinuxagent/common/osutil/redhat.py | 12 ++++++++++++
1d2ea3
 1 file changed, 12 insertions(+)
1d2ea3
1d2ea3
diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py
1d2ea3
index 5c397ae8..7dd36add 100644
1d2ea3
--- a/azurelinuxagent/common/osutil/redhat.py
1d2ea3
+++ b/azurelinuxagent/common/osutil/redhat.py
1d2ea3
@@ -158,3 +158,15 @@ class RedhatOSUtil(Redhat6xOSUtil):
1d2ea3
                 time.sleep(wait)
1d2ea3
             else:
1d2ea3
                 logger.warn("exceeded restart retries")
1d2ea3
+
1d2ea3
+    def set_dhcp_hostname(self, hostname):
1d2ea3
+        """
1d2ea3
+        Recent RHEL distributions use network manager instead of sysconfig files
1d2ea3
+        to configure network interfaces
1d2ea3
+        """
1d2ea3
+        ifname = self.get_if_name()
1d2ea3
+
1d2ea3
+        return_code = shellutil.run("nmcli device modify {0} ipv4.dhcp-hostname {1} ipv6.dhcp-hostname {1}".format(ifname, hostname))
1d2ea3
+
1d2ea3
+        if return_code != 0:
1d2ea3
+            logger.error("failed to set DHCP hostname for interface {0}: return code {1}".format(ifname, return_code))
1d2ea3
-- 
1d2ea3
2.31.1
1d2ea3