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

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