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

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