From f7d6eaef7311ac2484d48e67ec69e915b31e16e2 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 15 Apr 2016 12:02:51 -0400 Subject: 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 --- cloudinit/distros/debian.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'cloudinit/distros') 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) -- cgit v1.2.3