From c8e25ec39f7e201ec691ac92368ea38c57756865 Mon Sep 17 00:00:00 2001 From: Mohammed Gamal Date: Fri, 29 Jul 2022 13:02:16 +0200 Subject: [PATCH] redhat: Use NetworkManager to set DHCP hostnames on recent RHEL distros Recent versions of RHEL 8 and RHEL 9 started using NetworkManager to configure network intefaces instead of sysconfig files. Configurations are no longer stored in /etc/sysconfig/ifcfg-{interface}. Fix this for setting DHCP hostnames in those RHEL versions. --- azurelinuxagent/common/osutil/redhat.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py index 312dd1608..4b46a97ad 100644 --- a/azurelinuxagent/common/osutil/redhat.py +++ b/azurelinuxagent/common/osutil/redhat.py @@ -164,3 +164,15 @@ def restart_if(self, ifname, retries=3, wait=5): time.sleep(wait) else: logger.warn("exceeded restart retries") + + def set_dhcp_hostname(self, hostname): + """ + Recent RHEL distributions use network manager instead of sysconfig files + to configure network interfaces + """ + ifname = self.get_if_name() + + return_code = shellutil.run("nmcli device modify {0} ipv4.dhcp-hostname {1} ipv6.dhcp-hostname {1}".format(ifname, hostname)) + + if return_code != 0: + logger.error("failed to set DHCP hostname for interface {0}: return code {1}".format(ifname, return_code))