summaryrefslogtreecommitdiff
path: root/cloudinit/distros
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/distros')
-rwxr-xr-xcloudinit/distros/__init__.py13
-rw-r--r--cloudinit/distros/debian.py23
-rw-r--r--cloudinit/distros/rhel.py7
3 files changed, 24 insertions, 19 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index f3d395b9..803ac74e 100755
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -22,6 +22,7 @@ from cloudinit import log as logging
from cloudinit import net
from cloudinit.net import eni
from cloudinit.net import network_state
+from cloudinit.net import renderers
from cloudinit import ssh_util
from cloudinit import type_utils
from cloudinit import util
@@ -50,6 +51,7 @@ class Distro(object):
hostname_conf_fn = "/etc/hostname"
tz_zone_dir = "/usr/share/zoneinfo"
init_cmd = ['service'] # systemctl, service etc
+ renderer_configs = {}
def __init__(self, name, cfg, paths):
self._paths = paths
@@ -69,6 +71,17 @@ class Distro(object):
def _write_network_config(self, settings):
raise NotImplementedError()
+ def _supported_write_network_config(self, network_config):
+ priority = util.get_cfg_by_path(
+ self._cfg, ('network', 'renderers'), None)
+
+ name, render_cls = renderers.select(priority=priority)
+ LOG.debug("Selected renderer '%s' from priority list: %s",
+ name, priority)
+ renderer = render_cls(config=self.renderer_configs.get(name))
+ renderer.render_network_config(network_config=network_config)
+ return []
+
def _find_tz_file(self, tz):
tz_file = os.path.join(self.tz_zone_dir, str(tz))
if not os.path.isfile(tz_file):
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 48ccec8c..1101f02d 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -13,8 +13,6 @@ import os
from cloudinit import distros
from cloudinit import helpers
from cloudinit import log as logging
-from cloudinit.net import eni
-from cloudinit.net.network_state import parse_net_config_data
from cloudinit import util
from cloudinit.distros.parsers.hostname import HostnameConf
@@ -38,11 +36,18 @@ ENI_HEADER = """# This file is generated from information provided by
# network: {config: disabled}
"""
+NETWORK_CONF_FN = "/etc/network/interfaces.d/50-cloud-init.cfg"
+
class Distro(distros.Distro):
hostname_conf_fn = "/etc/hostname"
locale_conf_fn = "/etc/default/locale"
- network_conf_fn = "/etc/network/interfaces.d/50-cloud-init.cfg"
+ renderer_configs = {
+ 'eni': {
+ 'eni_path': NETWORK_CONF_FN,
+ 'eni_header': ENI_HEADER,
+ }
+ }
def __init__(self, name, cfg, paths):
distros.Distro.__init__(self, name, cfg, paths)
@@ -51,12 +56,6 @@ class Distro(distros.Distro):
# should only happen say once per instance...)
self._runner = helpers.Runners(paths)
self.osfamily = 'debian'
- self._net_renderer = eni.Renderer({
- 'eni_path': self.network_conf_fn,
- 'eni_header': ENI_HEADER,
- 'links_path_prefix': None,
- 'netrules_path': None,
- })
def apply_locale(self, locale, out_fn=None):
if not out_fn:
@@ -76,14 +75,12 @@ class Distro(distros.Distro):
self.package_command('install', pkgs=pkglist)
def _write_network(self, settings):
- util.write_file(self.network_conf_fn, settings)
+ util.write_file(NETWORK_CONF_FN, settings)
return ['all']
def _write_network_config(self, netconfig):
- ns = parse_net_config_data(netconfig)
- self._net_renderer.render_network_state("/", ns)
_maybe_remove_legacy_eth0()
- return []
+ return self._supported_write_network_config(netconfig)
def _bring_up_interfaces(self, device_names):
use_all = False
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index 7498c63a..372c7d0f 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -11,8 +11,6 @@
from cloudinit import distros
from cloudinit import helpers
from cloudinit import log as logging
-from cloudinit.net.network_state import parse_net_config_data
-from cloudinit.net import sysconfig
from cloudinit import util
from cloudinit.distros import net_util
@@ -49,16 +47,13 @@ class Distro(distros.Distro):
# should only happen say once per instance...)
self._runner = helpers.Runners(paths)
self.osfamily = 'redhat'
- self._net_renderer = sysconfig.Renderer()
cfg['ssh_svcname'] = 'sshd'
def install_packages(self, pkglist):
self.package_command('install', pkgs=pkglist)
def _write_network_config(self, netconfig):
- ns = parse_net_config_data(netconfig)
- self._net_renderer.render_network_state("/", ns)
- return []
+ return self._supported_write_network_config(netconfig)
def _write_network(self, settings):
# TODO(harlowja) fix this... since this is the ubuntu format