summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/distros/__init__.py7
-rw-r--r--cloudinit/distros/debian.py5
-rw-r--r--cloudinit/distros/opensuse.py47
-rw-r--r--cloudinit/distros/rhel.py49
-rw-r--r--cloudinit/sources/DataSourceConfigDrive.py2
-rw-r--r--tests/unittests/test_distros/test_netconfig.py111
6 files changed, 4 insertions, 217 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index b8a48e85..ac150bef 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -74,11 +74,10 @@ class Distro(object):
def install_packages(self, pkglist):
raise NotImplementedError()
- @abc.abstractmethod
def _write_network(self, settings):
- # In the future use the http://fedorahosted.org/netcf/
- # to write this blob out in a distro format
- raise NotImplementedError()
+ raise RuntimeError(
+ "Legacy function '_write_network' was called in distro '%s'.\n"
+ "_write_network_config needs implementation.\n" % self.name)
def _write_network_config(self, settings):
raise NotImplementedError()
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 33cc0bf1..d517fb88 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -109,11 +109,6 @@ class Distro(distros.Distro):
self.update_package_sources()
self.package_command('install', pkgs=pkglist)
- def _write_network(self, settings):
- # this is a legacy method, it will always write eni
- util.write_file(self.network_conf_fn["eni"], settings)
- return ['all']
-
def _write_network_config(self, netconfig):
_maybe_remove_legacy_eth0()
return self._supported_write_network_config(netconfig)
diff --git a/cloudinit/distros/opensuse.py b/cloudinit/distros/opensuse.py
index 1fe896aa..1bfe0478 100644
--- a/cloudinit/distros/opensuse.py
+++ b/cloudinit/distros/opensuse.py
@@ -16,7 +16,6 @@ from cloudinit import helpers
from cloudinit import log as logging
from cloudinit import util
-from cloudinit.distros import net_util
from cloudinit.distros import rhel_util as rhutil
from cloudinit.settings import PER_INSTANCE
@@ -172,52 +171,6 @@ class Distro(distros.Distro):
conf.set_hostname(hostname)
util.write_file(out_fn, str(conf), 0o644)
- def _write_network(self, settings):
- # Convert debian settings to ifcfg format
- entries = net_util.translate_network(settings)
- LOG.debug("Translated ubuntu style network settings %s into %s",
- settings, entries)
- # Make the intermediate format as the suse format...
- nameservers = []
- searchservers = []
- dev_names = entries.keys()
- for (dev, info) in entries.items():
- net_fn = self.network_script_tpl % (dev)
- route_fn = self.route_conf_tpl % (dev)
- mode = None
- if info.get('auto', None):
- mode = 'auto'
- else:
- mode = 'manual'
- bootproto = info.get('bootproto', None)
- gateway = info.get('gateway', None)
- net_cfg = {
- 'BOOTPROTO': bootproto,
- 'BROADCAST': info.get('broadcast'),
- 'GATEWAY': gateway,
- 'IPADDR': info.get('address'),
- 'LLADDR': info.get('hwaddress'),
- 'NETMASK': info.get('netmask'),
- 'STARTMODE': mode,
- 'USERCONTROL': 'no'
- }
- if dev != 'lo':
- net_cfg['ETHTOOL_OPTIONS'] = ''
- else:
- net_cfg['FIREWALL'] = 'no'
- rhutil.update_sysconfig_file(net_fn, net_cfg, True)
- if gateway and bootproto == 'static':
- default_route = 'default %s' % gateway
- util.write_file(route_fn, default_route, 0o644)
- if 'dns-nameservers' in info:
- nameservers.extend(info['dns-nameservers'])
- if 'dns-search' in info:
- searchservers.extend(info['dns-search'])
- if nameservers or searchservers:
- rhutil.update_resolve_conf_file(self.resolve_conf_fn,
- nameservers, searchservers)
- return dev_names
-
def _write_network_config(self, netconfig):
return self._supported_write_network_config(netconfig)
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index ff513438..f55d96f7 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -13,7 +13,6 @@ from cloudinit import helpers
from cloudinit import log as logging
from cloudinit import util
-from cloudinit.distros import net_util
from cloudinit.distros import rhel_util
from cloudinit.settings import PER_INSTANCE
@@ -65,54 +64,6 @@ class Distro(distros.Distro):
def _write_network_config(self, netconfig):
return self._supported_write_network_config(netconfig)
- def _write_network(self, settings):
- # TODO(harlowja) fix this... since this is the ubuntu format
- entries = net_util.translate_network(settings)
- LOG.debug("Translated ubuntu style network settings %s into %s",
- settings, entries)
- # Make the intermediate format as the rhel format...
- nameservers = []
- searchservers = []
- dev_names = entries.keys()
- use_ipv6 = False
- for (dev, info) in entries.items():
- net_fn = self.network_script_tpl % (dev)
- net_cfg = {
- 'DEVICE': dev,
- 'NETMASK': info.get('netmask'),
- 'IPADDR': info.get('address'),
- 'BOOTPROTO': info.get('bootproto'),
- 'GATEWAY': info.get('gateway'),
- 'BROADCAST': info.get('broadcast'),
- 'MACADDR': info.get('hwaddress'),
- 'ONBOOT': _make_sysconfig_bool(info.get('auto')),
- }
- if info.get('inet6'):
- use_ipv6 = True
- net_cfg.update({
- 'IPV6INIT': _make_sysconfig_bool(True),
- 'IPV6ADDR': info.get('ipv6').get('address'),
- 'IPV6_DEFAULTGW': info.get('ipv6').get('gateway'),
- })
- rhel_util.update_sysconfig_file(net_fn, net_cfg)
- if 'dns-nameservers' in info:
- nameservers.extend(info['dns-nameservers'])
- if 'dns-search' in info:
- searchservers.extend(info['dns-search'])
- if nameservers or searchservers:
- rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
- nameservers, searchservers)
- if dev_names:
- net_cfg = {
- 'NETWORKING': _make_sysconfig_bool(True),
- }
- # If IPv6 interface present, enable ipv6 networking
- if use_ipv6:
- net_cfg['NETWORKING_IPV6'] = _make_sysconfig_bool(True)
- net_cfg['IPV6_AUTOCONF'] = _make_sysconfig_bool(False)
- rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg)
- return dev_names
-
def apply_locale(self, locale, out_fn=None):
if self.uses_systemd():
if not out_fn:
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py
index 4cb28977..664dc4b7 100644
--- a/cloudinit/sources/DataSourceConfigDrive.py
+++ b/cloudinit/sources/DataSourceConfigDrive.py
@@ -196,7 +196,7 @@ def on_first_boot(data, distro=None, network=True):
net_conf = data.get("network_config", '')
if net_conf and distro:
LOG.warning("Updating network interfaces from config drive")
- distro.apply_network(net_conf)
+ distro.apply_network_config(eni.convert_eni_data(net_conf))
write_injected_files(data.get('files'))
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index 9bbff451..6e339355 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -367,16 +367,6 @@ class TestNetCfgDistroUbuntuEni(TestNetCfgDistroBase):
self.assertEqual(expected, results[cfgpath])
self.assertEqual(0o644, get_mode(cfgpath, tmpd))
- def test_simple_write_ub(self):
- expected_cfgs = {
- self.eni_path(): BASE_NET_CFG,
- }
-
- # ub_distro.apply_network(BASE_NET_CFG, False)
- self._apply_and_verify_eni(self.distro.apply_network,
- BASE_NET_CFG,
- expected_cfgs=expected_cfgs.copy())
-
def test_apply_network_config_eni_ub(self):
expected_cfgs = {
self.eni_path(): V1_NET_CFG_OUTPUT,
@@ -467,35 +457,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase):
self.assertCfgEquals(expected, results[cfgpath])
self.assertEqual(0o644, get_mode(cfgpath, tmpd))
- def test_simple_write_rh(self):
- expected_cfgs = {
- self.ifcfg_path('lo'): dedent("""\
- DEVICE="lo"
- ONBOOT=yes
- """),
- self.ifcfg_path('eth0'): dedent("""\
- DEVICE="eth0"
- BOOTPROTO="static"
- NETMASK="255.255.255.0"
- IPADDR="192.168.1.5"
- ONBOOT=yes
- GATEWAY="192.168.1.254"
- BROADCAST="192.168.1.0"
- """),
- self.ifcfg_path('eth1'): dedent("""\
- DEVICE="eth1"
- BOOTPROTO="dhcp"
- ONBOOT=yes
- """),
- self.control_path(): dedent("""\
- NETWORKING=yes
- """),
- }
- # rh_distro.apply_network(BASE_NET_CFG, False)
- self._apply_and_verify(self.distro.apply_network,
- BASE_NET_CFG,
- expected_cfgs=expected_cfgs.copy())
-
def test_apply_network_config_rh(self):
expected_cfgs = {
self.ifcfg_path('eth0'): dedent("""\
@@ -527,47 +488,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase):
V1_NET_CFG,
expected_cfgs=expected_cfgs.copy())
- def test_write_ipv6_rhel(self):
- expected_cfgs = {
- self.ifcfg_path('lo'): dedent("""\
- DEVICE="lo"
- ONBOOT=yes
- """),
- self.ifcfg_path('eth0'): dedent("""\
- DEVICE="eth0"
- BOOTPROTO="static"
- NETMASK="255.255.255.0"
- IPADDR="192.168.1.5"
- ONBOOT=yes
- GATEWAY="192.168.1.254"
- BROADCAST="192.168.1.0"
- IPV6INIT=yes
- IPV6ADDR="2607:f0d0:1002:0011::2"
- IPV6_DEFAULTGW="2607:f0d0:1002:0011::1"
- """),
- self.ifcfg_path('eth1'): dedent("""\
- DEVICE="eth1"
- BOOTPROTO="static"
- NETMASK="255.255.255.0"
- IPADDR="192.168.1.6"
- ONBOOT=no
- GATEWAY="192.168.1.254"
- BROADCAST="192.168.1.0"
- IPV6INIT=yes
- IPV6ADDR="2607:f0d0:1002:0011::3"
- IPV6_DEFAULTGW="2607:f0d0:1002:0011::1"
- """),
- self.control_path(): dedent("""\
- NETWORKING=yes
- NETWORKING_IPV6=yes
- IPV6_AUTOCONF=no
- """),
- }
- # rh_distro.apply_network(BASE_NET_CFG_IPV6, False)
- self._apply_and_verify(self.distro.apply_network,
- BASE_NET_CFG_IPV6,
- expected_cfgs=expected_cfgs.copy())
-
def test_apply_network_config_ipv6_rh(self):
expected_cfgs = {
self.ifcfg_path('eth0'): dedent("""\
@@ -627,37 +547,6 @@ class TestNetCfgDistroOpensuse(TestNetCfgDistroBase):
self.assertCfgEquals(expected, results[cfgpath])
self.assertEqual(0o644, get_mode(cfgpath, tmpd))
- def test_simple_write_opensuse(self):
- """Opensuse network rendering writes appropriate sysconfig files."""
- expected_cfgs = {
- self.ifcfg_path('lo'): dedent('''
- STARTMODE="auto"
- USERCONTROL="no"
- FIREWALL="no"
- '''),
- self.ifcfg_path('eth0'): dedent('''
- BOOTPROTO="static"
- BROADCAST="192.168.1.0"
- GATEWAY="192.168.1.254"
- IPADDR="192.168.1.5"
- NETMASK="255.255.255.0"
- STARTMODE="auto"
- USERCONTROL="no"
- ETHTOOL_OPTIONS=""
- '''),
- self.ifcfg_path('eth1'): dedent('''
- BOOTPROTO="dhcp"
- STARTMODE="auto"
- USERCONTROL="no"
- ETHTOOL_OPTIONS=""
- ''')
- }
-
- # distro.apply_network(BASE_NET_CFG, False)
- self._apply_and_verify(self.distro.apply_network,
- BASE_NET_CFG,
- expected_cfgs=expected_cfgs.copy())
-
def test_apply_network_config_opensuse(self):
"""Opensuse uses apply_network_config and renders sysconfig"""
expected_cfgs = {