From a2436a93ed867b58f2c9ac2484041b119f09860a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Wed, 11 Mar 2015 19:48:17 +0000 Subject: simple-network.configure: Rename networkd file generated by systemd chunk Rename instead removal in case the user is already using a 10-dhcp.network file --- morphlib/exts/simple-network.configure | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/morphlib/exts/simple-network.configure b/morphlib/exts/simple-network.configure index 7c078c93..a347ebf9 100755 --- a/morphlib/exts/simple-network.configure +++ b/morphlib/exts/simple-network.configure @@ -47,6 +47,8 @@ class SimpleNetworkConfigurationExtension(cliapp.Application): def process_args(self, args): network_config = os.environ.get("NETWORK_CONFIG") + self.rename_networkd_chunk_file(args) + if network_config is None: self.generate_default_network_config(args) else: @@ -57,6 +59,33 @@ class SimpleNetworkConfigurationExtension(cliapp.Application): self.generate_interfaces_file(args, stanzas) self.generate_networkd_files(args, stanzas) + def rename_networkd_chunk_file(self, args): + """Rename the 10-dchp.network file generated in the systemd chunk + + The systemd chunk will place something in 10-dhcp.network, which will + have higher precedence than anything added in this extension (we + start at 50-*). + + We should check for that file and rename it instead remove it in + case the file is being used by the user. + + Until both the following happen, we should continue to rename that + default config file: + + 1. simple-network.configure is always run when systemd is included + 2. We've been building systems without systemd including that default + networkd config for long enough that nobody should be including + that config file. + """ + file_path = os.path.join(args[0], "etc", "systemd", "network", + "10-dhcp.network") + try: + os.rename(file_path, file_path + ".morph") + self.status(msg="Renaming networkd file from systemd chunk: %(f)s \ + to %(f)s.morph", f=file_path) + except OSError: + pass + def generate_default_network_config(self, args): """Generate default network configuration: DHCP in all the interfaces""" -- cgit v1.2.1