← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~brak/cloud-init/centos-7-fixes into lp:cloud-init

 

Brian Rak has proposed merging lp:~brak/cloud-init/centos-7-fixes into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~brak/cloud-init/centos-7-fixes/+merge/256340

cloud-init was not detecting that CentOS 7 uses systemd.

Also, on RHEL-type systems using systemd, /var/lib/cloud/data/previous-hostname would never get created (because rather then write to files, it was executing hostnamectl)
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~brak/cloud-init/centos-7-fixes into lp:cloud-init.
=== modified file 'cloudinit/distros/rhel.py'
--- cloudinit/distros/rhel.py	2015-01-21 22:56:53 +0000
+++ cloudinit/distros/rhel.py	2015-04-15 15:21:22 +0000
@@ -116,6 +116,7 @@
         (dist, vers) = util.system_info()['dist'][:2]
         major = (int)(vers.split('.')[0])
         return ((dist.startswith('Red Hat Enterprise Linux') and major >= 7)
+                or (dist.startswith('CentOS Linux') and major >= 7)
                 or (dist.startswith('Fedora') and major >= 18))
 
     def apply_locale(self, locale, out_fn=None):
@@ -132,7 +133,11 @@
         rhel_util.update_sysconfig_file(out_fn, locale_cfg)
 
     def _write_hostname(self, hostname, out_fn):
-        if self.uses_systemd():
+        # systemd will never update previous-hostname for us, so 
+        # we need to do it ourselves
+        if self.uses_systemd() and out_fn.endswith('/previous-hostname'):
+            util.write_file(out_fn, hostname)
+        elif self.uses_systemd():
             util.subp(['hostnamectl', 'set-hostname', str(hostname)])
         else:
             host_cfg = {
@@ -155,7 +160,9 @@
         return (host_fn, self._read_hostname(host_fn))
 
     def _read_hostname(self, filename, default=None):
-        if self.uses_systemd():
+        if self.uses_systemd() and filename.endswith('/previous-hostname'):
+            return util.load_file(filename).strip()  
+        elif self.uses_systemd():
             (out, _err) = util.subp(['hostname'])
             if len(out):
                 return out


Follow ups