Hello community,

here is the log from the commit of package python-azure-agent for 
openSUSE:Factory checked in at 2020-07-27 17:38:27
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-azure-agent (Old)
 and      /work/SRC/openSUSE:Factory/.python-azure-agent.new.3592 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-azure-agent"

Mon Jul 27 17:38:27 2020 rev:14 rq:822699 version:2.2.45

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-azure-agent/python-azure-agent.changes    
2020-04-01 19:14:29.707427368 +0200
+++ 
/work/SRC/openSUSE:Factory/.python-azure-agent.new.3592/python-azure-agent.changes
  2020-07-27 17:38:39.286900415 +0200
@@ -1,0 +2,8 @@
+Fri Jul 17 17:20:01 UTC 2020 - Robert Schweikert <[email protected]>
+
+- Add proper_dhcp_config_set.patch (bsc#1173866)
+  + Properly set the dhcp configuration to push the hostname to the DHCP
+    server
+  + Do not bring the interface down to push the hostname, just use ifup
+
+-------------------------------------------------------------------

New:
----
  proper_dhcp_config_set.patch

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-azure-agent.spec ++++++
--- /var/tmp/diff_new_pack.mD3ygp/_old  2020-07-27 17:38:40.538901633 +0200
+++ /var/tmp/diff_new_pack.mD3ygp/_new  2020-07-27 17:38:40.538901633 +0200
@@ -28,6 +28,7 @@
 Patch6:         paa_force_py3_sle15.patch
 Patch9:         paa_sudo_sle15_nopwd.patch
 Patch10:        paa_use_hostnamectl.patch
+Patch11:        proper_dhcp_config_set.patch
 BuildRequires:  dos2unix
 
 BuildRequires:  distribution-release
@@ -124,6 +125,7 @@
 %patch9
 %endif
 %patch10
+%patch11
 
 %build
 %if 0%{?suse_version} && 0%{?suse_version} > 1315

++++++ proper_dhcp_config_set.patch ++++++
--- azurelinuxagent/common/osutil/suse.py.orig
+++ azurelinuxagent/common/osutil/suse.py
@@ -16,20 +16,12 @@
 # Requires Python 2.6+ and Openssl 1.0+
 #
 
-import os
-import re
-import pwd
-import shutil
-import socket
-import array
-import struct
-import fcntl
 import time
+
 import azurelinuxagent.common.logger as logger
 import azurelinuxagent.common.utils.fileutil as fileutil
 import azurelinuxagent.common.utils.shellutil as shellutil
-import azurelinuxagent.common.utils.textutil as textutil
-from azurelinuxagent.common.version import DISTRO_NAME, DISTRO_VERSION, 
DISTRO_FULL_NAME
+
 from azurelinuxagent.common.osutil.default import DefaultOSUtil
 
 
@@ -82,11 +74,64 @@ class SUSEOSUtil(SUSE11OSUtil):
         super(SUSEOSUtil, self).__init__()
         self.dhclient_name = 'wickedd-dhcp4'
 
+    def publish_hostname(self, hostname):
+        self.set_dhcp_hostname(hostname)
+        self.set_hostname_record(hostname)
+        ifname = self.get_if_name()
+        # To push the hostname to the dhcp server we do not need to
+        # bring down the interface, just make the make ifup do whatever is
+        # necessary
+        self.ifup(ifname)
+
+    def ifup(self, ifname, retries=3, wait=5):
+        logger.info('Interface {0} bounce with ifup'.format(ifname))
+        retry_limit=retries+1
+        for attempt in range(1, retry_limit):
+            try:
+                shellutil.run_command(['ifup', ifname], log_error=True)
+            except Exception:
+                if attempt < retry_limit:
+                    logger.info("retrying in {0} seconds".format(wait))
+                    time.sleep(wait)
+                else:
+                    logger.warn("exceeded restart retries")
+
     def set_hostname(self, hostname):
         shellutil.run(
             "hostnamectl set-hostname {0}".format(hostname), chk_err=False
         )
 
+    def set_dhcp_hostname(self, hostname):
+        dhcp_config_file_path = '/etc/sysconfig/network/dhcp'
+        hostname_send_setting = fileutil.get_line_startingwith(
+            'DHCLIENT_HOSTNAME_OPTION', dhcp_config_file_path
+        )
+        if hostname_send_setting:
+            value = hostname_send_setting.split('=')[-1]
+            if value == "AUTO" or value == '"{0}"'.format(hostname):
+                # Return if auto send host-name is configured or the current
+                # hostname is already set up to be sent
+                return
+            else:
+                # Do not use update_conf_file as it moves the setting to the
+                # end of the file separating it from the contextual comment
+                new_conf = []
+                dhcp_conf = fileutil.read_file(
+                    dhcp_config_file_path).split('\n')
+                for entry in dhcp_conf:
+                    if entry.startswith('DHCLIENT_HOSTNAME_OPTION'):
+                        new_conf.append(
+                           'DHCLIENT_HOSTNAME_OPTION="{0}"'. format(hostname)
+                        )
+                        continue
+                    new_conf.append(entry)
+                fileutil.write_file(dhcp_config_file_path, '\n'.join(new_conf))
+        else:
+            fileutil.append_file(
+                dhcp_config_file_path,
+                'DHCLIENT_HOSTNAME_OPTION="{0}"'. format(hostname)
+            )
+
     def stop_dhcp_service(self):
         cmd = "systemctl stop {0}".format(self.dhclient_name)
         return shellutil.run(cmd, chk_err=False)

Reply via email to