summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorharlowja <harlowja@virtualbox.rhel>2012-06-17 13:48:53 -0700
committerharlowja <harlowja@virtualbox.rhel>2012-06-17 13:48:53 -0700
commit47f9f64a03c90ea08b6e363f786dfee921345682 (patch)
tree0bdac833eec44ae8ea001c25f52af26cac31a732
parent4e5e0dadf07d52d92711ee674d98ee0ef523ea6a (diff)
downloadvyos-cloud-init-47f9f64a03c90ea08b6e363f786dfee921345682.tar.gz
vyos-cloud-init-47f9f64a03c90ea08b6e363f786dfee921345682.zip
1. Adjust the ubuntu network hostname writing to go through a standard write function
2. Add comment as to why we search for "#" when reading
-rw-r--r--cloudinit/distros/ubuntu.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/cloudinit/distros/ubuntu.py b/cloudinit/distros/ubuntu.py
index ec4d6b5b..786974ad 100644
--- a/cloudinit/distros/ubuntu.py
+++ b/cloudinit/distros/ubuntu.py
@@ -49,11 +49,14 @@ class Distro(distros.Distro):
util.write_file("/etc/network/interfaces", settings)
def set_hostname(self, hostname):
- contents = "%s\n" % (hostname)
- util.write_file("/etc/hostname", contents, 0644)
+ self._write_hostname(hostname, "/etc/hostname")
LOG.debug("Setting hostname to %s", hostname)
util.subp(['hostname', hostname])
+ def _write_hostname(self, hostname, out_fn):
+ contents = "%s\n" % (hostname)
+ util.write_file(out_fn, contents, 0644)
+
def update_hostname(self, hostname, prev_file):
hostname_prev = self._read_hostname(prev_file)
hostname_in_etc = self._read_hostname("/etc/hostname")
@@ -65,8 +68,7 @@ class Distro(distros.Distro):
update_files.append("/etc/hostname")
for fn in update_files:
try:
- contents = "%s\n" % (hostname)
- util.write_file(fn, contents, 0644)
+ self._write_hostname(hostname, fn)
except:
util.logexc(LOG, "Failed to write hostname %s to %s",
hostname, fn)
@@ -82,11 +84,12 @@ class Distro(distros.Distro):
contents = util.load_file(filename, quiet=True)
for line in contents.splitlines():
hpos = line.find("#")
+ # Handle inline comments
if hpos != -1:
line = line[0:hpos]
- line = line.rstrip()
- if line:
- return line
+ line_c = line.strip()
+ if line_c:
+ return line_c
return default
def _get_localhost_ip(self):