diff options
author | Wesley Wiedenmeier <wesley.wiedenmeier@gmail.com> | 2016-03-21 21:10:20 -0500 |
---|---|---|
committer | Wesley Wiedenmeier <wesley.wiedenmeier@gmail.com> | 2016-03-21 21:10:20 -0500 |
commit | 9a146e83189ef3128a04c9e0c1d21c6181f554f1 (patch) | |
tree | 3ef35dc7e6d2ddb450ee3037308284df052d1488 | |
parent | bb58463474e334b8c8d1769101bd3afc48ebfef4 (diff) | |
download | vyos-cloud-init-9a146e83189ef3128a04c9e0c1d21c6181f554f1.tar.gz vyos-cloud-init-9a146e83189ef3128a04c9e0c1d21c6181f554f1.zip |
Added _write_network_fallback function to distros.debian and abstract to
distros base, and apply_fallback_network to distros to call
_write_network_fallback. Note that since _write_network_fallback is only
implemented for debian and ubuntu a check is needed to ensure that it does not
break behaviour for other distros.
Added function to disable .cfg files to util, since it may be useful elsewhere
-rw-r--r-- | cloudinit/distros/__init__.py | 12 | ||||
-rw-r--r-- | cloudinit/distros/debian.py | 10 | ||||
-rw-r--r-- | cloudinit/util.py | 9 |
3 files changed, 31 insertions, 0 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 74b484a7..e32ddd57 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -78,6 +78,10 @@ class Distro(object): def _write_network_config(self, settings): raise NotImplementedError() + @abc.abstractmethod + def _write_network_fallback(self): + raise NotImplementedError() + def _find_tz_file(self, tz): tz_file = os.path.join(self.tz_zone_dir, str(tz)) if not os.path.isfile(tz_file): @@ -143,6 +147,14 @@ class Distro(object): return self._bring_up_interfaces(dev_names) return False + def apply_fallback_network(self, bring_up=True): + # Write it out + dev_names = self._write_network_fallback() + # Now try to bring them up + if bring_up: + return self._bring_up_interfaces(dev_names) + return False + @abc.abstractmethod def apply_locale(self, locale, out_fn=None): raise NotImplementedError() diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py index 909d6deb..18d5d124 100644 --- a/cloudinit/distros/debian.py +++ b/cloudinit/distros/debian.py @@ -82,6 +82,16 @@ class Distro(distros.Distro): net.render_network_state(network_state=ns, target="/") return [] + def _write_network_fallback(self): + # old fallback configuration is obsolete, disable it + util.disable_cfg_file('/etc/network/interfaces.d/eth0.cfg') + (ns, link_file, syslink_name) = net.find_fallback_network_device() + if link_file is not None: + util.write_file(syslink_name, link_file) + if ns is not None: + net.render_network_stat(network_state=ns, target="/") + return [] + def _bring_up_interfaces(self, device_names): use_all = False for d in device_names: diff --git a/cloudinit/util.py b/cloudinit/util.py index 20916e53..fa3a6163 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -849,6 +849,15 @@ def read_seeded(base="", ext="", timeout=5, retries=10, file_retries=0): return (md, ud) +def disable_conf_file(conf): + # disable .cfg file by renaming it if it exists + if not os.path.exists(conf): + return None + target_path = os.path.join(conf, '.disabled') + rename(conf, target_path) + return target_path + + def read_conf_d(confd): # Get reverse sorted list (later trumps newer) confs = sorted(os.listdir(confd), reverse=True) |