Commit f7d6eaef authored by Scott Moser's avatar Scott Moser

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
parent e660c36e
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment