summaryrefslogtreecommitdiff
path: root/cloudinit/distros/debian.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2016-08-23 16:48:42 -0400
committerScott Moser <smoser@brickies.net>2016-08-23 16:48:42 -0400
commite34dfab9fa310324f835ff4fbb2cf0a414b4d65e (patch)
treef166c7dfc532514c57dfae4daaab691687f8f100 /cloudinit/distros/debian.py
parent06fc05ea20bf42e2fe29d3c9810994e1f7158564 (diff)
parentb029dcefe1ed33be8ed80f2e376ca6874dfd64f7 (diff)
downloadvyos-cloud-init-e34dfab9fa310324f835ff4fbb2cf0a414b4d65e.tar.gz
vyos-cloud-init-e34dfab9fa310324f835ff4fbb2cf0a414b4d65e.zip
merge trunk at 0.7.7~bzr1212
Diffstat (limited to 'cloudinit/distros/debian.py')
-rw-r--r--cloudinit/distros/debian.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 5d7e6cfc..75ab340f 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -84,7 +84,8 @@ class Distro(distros.Distro):
eni=self.network_conf_fn,
links_prefix=self.links_prefix,
netrules=None)
- util.del_file("/etc/network/interfaces.d/eth0.cfg")
+ _maybe_remove_legacy_eth0()
+
return []
def _bring_up_interfaces(self, device_names):
@@ -193,3 +194,34 @@ def _get_wrapper_prefix(cmd, mode):
return cmd
else:
return []
+
+
+def _maybe_remove_legacy_eth0(path="/etc/network/interfaces.d/eth0.cfg"):
+ """Ubuntu cloud images previously included a 'eth0.cfg' that had
+ hard coded content. That file would interfere with the rendered
+ configuration if it was present.
+
+ if the file does not exist do nothing.
+ If the file exists:
+ - with known content, remove it and warn
+ - with unknown content, leave it and warn
+ """
+
+ if not os.path.exists(path):
+ return
+
+ bmsg = "Dynamic networking config may not apply."
+ try:
+ contents = util.load_file(path)
+ known_contents = ["auto eth0", "iface eth0 inet dhcp"]
+ lines = [f.strip() for f in contents.splitlines()
+ if not f.startswith("#")]
+ if lines == known_contents:
+ util.del_file(path)
+ msg = "removed %s with known contents" % path
+ else:
+ msg = (bmsg + " '%s' exists with user configured content." % path)
+ except:
+ msg = bmsg + " %s exists, but could not be read." % path
+
+ LOG.warn(msg)