summaryrefslogtreecommitdiff
path: root/azurelinuxagent/common/osutil/redhat.py
diff options
context:
space:
mode:
authorƁukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com>2017-03-15 10:19:34 +0100
committerusd-importer <ubuntu-server@lists.ubuntu.com>2017-03-17 13:08:24 +0000
commitc6339c307f36f77a4198d6faf1275acdf371200b (patch)
treec774046e1e30617514c09e5a2b896568706a25a8 /azurelinuxagent/common/osutil/redhat.py
parentdd73af563850762aad64e7ed2a9897377830af10 (diff)
parent2bc77af05fe602a2ba92569428c6006d1aebd19f (diff)
downloadvyos-walinuxagent-c6339c307f36f77a4198d6faf1275acdf371200b.tar.gz
vyos-walinuxagent-c6339c307f36f77a4198d6faf1275acdf371200b.zip
Import patches-applied version 2.2.6-0ubuntu1 to applied/ubuntu/zesty-proposed
Imported using git-ubuntu import. Changelog parent: dd73af563850762aad64e7ed2a9897377830af10 Unapplied parent: 2bc77af05fe602a2ba92569428c6006d1aebd19f New changelog entries: * New upstream release (LP: #1661750). * debian/control: - Change the maintainer to Ubuntu Developers (LP: #1657528). - Add the dependency of isc-dhcp-client as our maintainer scripts assume it's installed. - Add trailing commas to dependencies, add whitespaces. * Rename ephemeral-disk-warning.sh to ephemeral-disk-warning (lintian error). * debian/docs: - Remove LICENSE.txt as it's redundant. * debian/postinst: - Stop checking for update-initramfs existence using the absolute path, use the 'command' command instead to make lintian happy. * Remove debian/patches/disable-auto-update.patch: - We now ship with auto-updates enabled (LP: #1650522). * debian/maintscript: - Add a maintscript to rename the old logrotate file on upgrade from an ancient version of walinuxagent (LP: #1673152).
Diffstat (limited to 'azurelinuxagent/common/osutil/redhat.py')
-rw-r--r--azurelinuxagent/common/osutil/redhat.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py
index 80370a2..5254ea5 100644
--- a/azurelinuxagent/common/osutil/redhat.py
+++ b/azurelinuxagent/common/osutil/redhat.py
@@ -36,6 +36,7 @@ import azurelinuxagent.common.utils.textutil as textutil
from azurelinuxagent.common.utils.cryptutil import CryptUtil
from azurelinuxagent.common.osutil.default import DefaultOSUtil
+
class Redhat6xOSUtil(DefaultOSUtil):
def __init__(self):
super(Redhat6xOSUtil, self).__init__()
@@ -57,7 +58,7 @@ class Redhat6xOSUtil(DefaultOSUtil):
def unregister_agent_service(self):
return shellutil.run("chkconfig --del waagent", chk_err=False)
-
+
def openssl_to_openssh(self, input_file, output_file):
pubkey = fileutil.read_file(input_file)
try:
@@ -67,7 +68,7 @@ class Redhat6xOSUtil(DefaultOSUtil):
raise OSUtilError(ustr(e))
fileutil.write_file(output_file, ssh_rsa_pubkey)
- #Override
+ # Override
def get_dhcp_pid(self):
ret = shellutil.run_get_output("pidof dhclient", chk_err=False)
return ret[1] if ret[0] == 0 else None
@@ -84,22 +85,28 @@ class Redhat6xOSUtil(DefaultOSUtil):
def set_dhcp_hostname(self, hostname):
ifname = self.get_if_name()
filepath = "/etc/sysconfig/network-scripts/ifcfg-{0}".format(ifname)
- fileutil.update_conf_file(filepath, 'DHCP_HOSTNAME',
+ fileutil.update_conf_file(filepath,
+ 'DHCP_HOSTNAME',
'DHCP_HOSTNAME={0}'.format(hostname))
def get_dhcp_lease_endpoint(self):
return self.get_endpoint_from_leases_path('/var/lib/dhclient/dhclient-*.leases')
+
class RedhatOSUtil(Redhat6xOSUtil):
def __init__(self):
super(RedhatOSUtil, self).__init__()
def set_hostname(self, hostname):
"""
- Set /etc/hostname
- Unlike redhat 6.x, redhat 7.x will set hostname to /etc/hostname
+ Unlike redhat 6.x, redhat 7.x will set hostname via hostnamectl
+ Due to a bug in systemd in Centos-7.0, if this call fails, fallback
+ to hostname.
"""
- DefaultOSUtil.set_hostname(self, hostname)
+ hostnamectl_cmd = "hostnamectl set-hostname {0}".format(hostname)
+ if shellutil.run(hostnamectl_cmd, chk_err=False) != 0:
+ logger.warn("[{0}] failed, attempting fallback".format(hostnamectl_cmd))
+ DefaultOSUtil.set_hostname(self, hostname)
def publish_hostname(self, hostname):
"""
@@ -118,5 +125,11 @@ class RedhatOSUtil(Redhat6xOSUtil):
DefaultOSUtil.openssl_to_openssh(self, input_file, output_file)
def get_dhcp_lease_endpoint(self):
- # centos7 has this weird naming with double hyphen like /var/lib/dhclient/dhclient--eth0.lease
- return self.get_endpoint_from_leases_path('/var/lib/dhclient/dhclient-*.lease')
+ # dhclient
+ endpoint = self.get_endpoint_from_leases_path('/var/lib/dhclient/dhclient-*.lease')
+
+ if endpoint is None:
+ # NetworkManager
+ endpoint = self.get_endpoint_from_leases_path('/var/lib/NetworkManager/dhclient-*.lease')
+
+ return endpoint