summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-04-15 12:02:51 -0400
committerScott Moser <smoser@ubuntu.com>2016-04-15 12:02:51 -0400
commitf7d6eaef7311ac2484d48e67ec69e915b31e16e2 (patch)
treeec8f345570fda12af8ed39e8193817b232059cae /cloudinit
parente660c36e61764c2236ddc8c45d8ffe95a16f2e39 (diff)
downloadvyos-cloud-init-f7d6eaef7311ac2484d48e67ec69e915b31e16e2.tar.gz
vyos-cloud-init-f7d6eaef7311ac2484d48e67ec69e915b31e16e2.zip
networking: no longer delete eth0.cfg on debian/ubuntu
Ubuntu cloud images in created a file during build that would interfere with cloud-init's discovered or rendered networking. To avoid the issues, cloud-init was deleting /etc/network/interfaces.d/eth0.cfg . The build process no longer creates this file. However, to address any existing files cloud-init will still remove the file if it has known content and warn otherwise. LP: #1563487
Diffstat (limited to 'cloudinit')
-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)