Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP1:GA
python-azure-agent.16452
proper_dhcp_config_set.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File proper_dhcp_config_set.patch of Package python-azure-agent.16452
--- azurelinuxagent/common/osutil/suse.py.orig +++ azurelinuxagent/common/osutil/suse.py @@ -69,9 +69,62 @@ 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): self._run_command_without_raising(["hostnamectl", "set-hostname", hostname], log_error=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): self._run_command_without_raising(["systemctl", "stop", "{}.service".format(self.dhclient_name)], log_error=False)
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor