summaryrefslogtreecommitdiff
path: root/cloudinit/distros
diff options
context:
space:
mode:
authorbrak <brak@brian2>2015-04-15 11:32:56 -0400
committerbrak <brak@brian2>2015-04-15 11:32:56 -0400
commit96820355ea20fe655a7ebbb68ffb309bf234ab37 (patch)
tree20bba2c4aca641622bf47cb677629c5143d3734c /cloudinit/distros
parentf4789639af50ea631cf75af526ad013b05670caa (diff)
downloadvyos-cloud-init-96820355ea20fe655a7ebbb68ffb309bf234ab37.tar.gz
vyos-cloud-init-96820355ea20fe655a7ebbb68ffb309bf234ab37.zip
Don't overwrite the hostname if the user has changed it after we set it
Diffstat (limited to 'cloudinit/distros')
-rw-r--r--cloudinit/distros/__init__.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index ab874b45..c699a65a 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -208,6 +208,15 @@ class Distro(object):
and sys_hostname != hostname):
update_files.append(sys_fn)
+ # If something else has changed the hostname after we set it
+ # initially, we should not overwrite those changes (we should
+ # only be setting the hostname once per instance)
+ if (sys_hostname and prev_hostname and
+ sys_hostname != prev_hostname):
+ LOG.info("%s differs from %s, assuming user maintained hostname.",
+ prev_hostname_fn, sys_fn)
+ return
+
# Remove duplicates (incase the previous config filename)
# is the same as the system config filename, don't bother
# doing it twice
@@ -222,11 +231,6 @@ class Distro(object):
util.logexc(LOG, "Failed to write hostname %s to %s", hostname,
fn)
- if (sys_hostname and prev_hostname and
- sys_hostname != prev_hostname):
- LOG.debug("%s differs from %s, assuming user maintained hostname.",
- prev_hostname_fn, sys_fn)
-
# If the system hostname file name was provided set the
# non-fqdn as the transient hostname.
if sys_fn in update_files: