summaryrefslogtreecommitdiff
path: root/cloudinit/distros/debian.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-11-13 18:41:31 -0500
committerScott Moser <smoser@ubuntu.com>2012-11-13 18:41:31 -0500
commit8ae9c57ca05a0f99131a6693c109cbb52c0f0d4d (patch)
tree6df7295f5eab5740761b598ebfe545a06b88a8f0 /cloudinit/distros/debian.py
parente016e7c7837c70f5fce0c3b3d9bd944a8d43f9f0 (diff)
parente91fbc058cdd709a561863202231076788323782 (diff)
downloadvyos-cloud-init-8ae9c57ca05a0f99131a6693c109cbb52c0f0d4d.tar.gz
vyos-cloud-init-8ae9c57ca05a0f99131a6693c109cbb52c0f0d4d.zip
Only attempt to read the previous hostname file if it exists.
- Instead of always reading the previous hostname file even if it did not exist lets only read it if it is a valid variable and is actually a existent file instead of just attempting to read it always. - Also update the logging that is done when a previous file does not exist. LP: #1078452
Diffstat (limited to 'cloudinit/distros/debian.py')
-rw-r--r--cloudinit/distros/debian.py38
1 files changed, 19 insertions, 19 deletions
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index b6e7654f..7422f4f0 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -88,37 +88,37 @@ class Distro(distros.Distro):
return hostname
def _write_hostname(self, your_hostname, out_fn):
- conf = self._read_hostname_conf(out_fn)
+ conf = None
+ try:
+ # Try to update the previous one
+ # so lets see if we can read it first.
+ conf = self._read_hostname_conf(out_fn)
+ except IOError:
+ pass
if not conf:
conf = HostnameConf('')
- conf.parse()
conf.set_hostname(your_hostname)
util.write_file(out_fn, str(conf), 0644)
def _read_system_hostname(self):
- conf = self._read_hostname_conf(self.hostname_conf_fn)
- if conf:
- sys_hostname = conf.hostname
- else:
- sys_hostname = None
+ sys_hostname = self._read_hostname(self.hostname_conf_fn)
return (self.hostname_conf_fn, sys_hostname)
def _read_hostname_conf(self, filename):
- try:
- conf = HostnameConf(util.load_file(filename))
- conf.parse()
- return conf
- except IOError:
- util.logexc(LOG, "Error reading hostname from %s", filename)
- return None
+ conf = HostnameConf(util.load_file(filename))
+ conf.parse()
+ return conf
def _read_hostname(self, filename, default=None):
- conf = self._read_hostname_conf(filename)
- if not conf:
- return default
- if not conf.hostname:
+ hostname = None
+ try:
+ conf = self._read_hostname_conf(filename)
+ hostname = conf.hostname
+ except IOError:
+ pass
+ if not hostname:
return default
- return conf.hostname
+ return hostname
def _get_localhost_ip(self):
# Note: http://www.leonardoborda.com/blog/127-0-1-1-ubuntu-debian/