From 4b123c3524b35e850f3b3724ebdf6f57eb214350 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 20 Jun 2016 14:54:12 -0400 Subject: leave early if no interfaces to rename --- cloudinit/net/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py index 6959ad34..63e54f91 100644 --- a/cloudinit/net/__init__.py +++ b/cloudinit/net/__init__.py @@ -237,6 +237,11 @@ def _get_current_rename_info(check_downable=True): def _rename_interfaces(renames, strict_present=True, strict_busy=True, current_info=None): + + if not len(renames): + LOG.debug("no interfaces to rename") + return + if current_info is None: current_info = _get_current_rename_info() -- cgit v1.2.1 From 0f0a75530de14c90a744cc751b151ee45f578096 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 20 Jun 2016 14:54:37 -0400 Subject: do not render systemd.link files on debian. These are unnecessary, as cloud-init is renaming the nics that should be renamed itself. --- cloudinit/distros/debian.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py index 53f3aa4d..244af349 100644 --- a/cloudinit/distros/debian.py +++ b/cloudinit/distros/debian.py @@ -59,7 +59,7 @@ class Distro(distros.Distro): self.osfamily = 'debian' self._net_renderer = eni.Renderer({ 'eni_path': self.network_conf_fn, - 'links_prefix_path': self.links_prefix, + 'links_prefix_path': None, 'netrules_path': None, }) -- cgit v1.2.1 From e9d1c04cdfe407d74bfd97b46cf5def84c588ff3 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 20 Jun 2016 17:07:10 -0400 Subject: add a header to rendered ENI file describing its content --- cloudinit/distros/debian.py | 8 ++++++++ cloudinit/net/eni.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py index 244af349..5ae9a509 100644 --- a/cloudinit/distros/debian.py +++ b/cloudinit/distros/debian.py @@ -43,6 +43,13 @@ APT_GET_WRAPPER = { 'enabled': 'auto', } +ENI_HEADER = """# This file is generated from information provided by +# the datasource. Changes to it will not persist across an instance. +# To disable cloud-init's network configuration capabilities, write a file +# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: +# network: {config: disabled} +""" + class Distro(distros.Distro): hostname_conf_fn = "/etc/hostname" @@ -59,6 +66,7 @@ class Distro(distros.Distro): self.osfamily = 'debian' self._net_renderer = eni.Renderer({ 'eni_path': self.network_conf_fn, + 'eni_header': ENI_HEADER, 'links_prefix_path': None, 'netrules_path': None, }) diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py index ccd16ba7..e5ed10fd 100644 --- a/cloudinit/net/eni.py +++ b/cloudinit/net/eni.py @@ -303,6 +303,7 @@ class Renderer(renderer.Renderer): if not config: config = {} self.eni_path = config.get('eni_path', 'etc/network/interfaces') + self.eni_header = config.get('eni_header', None) self.links_path_prefix = config.get( 'links_path_prefix', 'etc/systemd/network/50-cloud-init-') self.netrules_path = config.get( @@ -417,7 +418,8 @@ class Renderer(renderer.Renderer): def render_network_state(self, target, network_state): fpeni = os.path.join(target, self.eni_path) util.ensure_dir(os.path.dirname(fpeni)) - util.write_file(fpeni, self._render_interfaces(network_state)) + header = self.eni_header if self.eni_header else "" + util.write_file(fpeni, header + self._render_interfaces(network_state)) if self.netrules_path: netrules = os.path.join(target, self.netrules_path) -- cgit v1.2.1