~oddbloke/cloud-init/fix-gce-az

« back to all changes in this revision

Viewing changes to cloudinit/distros/rhel.py

  • Committer: Scott Moser
  • Date: 2015-05-15 14:53:10 UTC
  • mfrom: (1089.4.1 cloud-init)
  • Revision ID: smoser@ubuntu.com-20150515145310-rtr4jxhzefd81sfq
detect that CentOS 7 uses systemd, write previous-hostname in that case.

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)

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
        (dist, vers) = util.system_info()['dist'][:2]
117
117
        major = (int)(vers.split('.')[0])
118
118
        return ((dist.startswith('Red Hat Enterprise Linux') and major >= 7)
 
119
                or (dist.startswith('CentOS Linux') and major >= 7)
119
120
                or (dist.startswith('Fedora') and major >= 18))
120
121
 
121
122
    def apply_locale(self, locale, out_fn=None):
132
133
        rhel_util.update_sysconfig_file(out_fn, locale_cfg)
133
134
 
134
135
    def _write_hostname(self, hostname, out_fn):
135
 
        if self.uses_systemd():
 
136
        # systemd will never update previous-hostname for us, so 
 
137
        # we need to do it ourselves
 
138
        if self.uses_systemd() and out_fn.endswith('/previous-hostname'):
 
139
            util.write_file(out_fn, hostname)
 
140
        elif self.uses_systemd():
136
141
            util.subp(['hostnamectl', 'set-hostname', str(hostname)])
137
142
        else:
138
143
            host_cfg = {
155
160
        return (host_fn, self._read_hostname(host_fn))
156
161
 
157
162
    def _read_hostname(self, filename, default=None):
158
 
        if self.uses_systemd():
 
163
        if self.uses_systemd() and filename.endswith('/previous-hostname'):
 
164
            return util.load_file(filename).strip()  
 
165
        elif self.uses_systemd():
159
166
            (out, _err) = util.subp(['hostname'])
160
167
            if len(out):
161
168
                return out