summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-03-22 05:40:05 -0400
committerScott Moser <smoser@ubuntu.com>2016-03-22 05:40:05 -0400
commit7f0871dc5b141ff4bf601b6d96021eba8a3bb0ec (patch)
treeaafd702015714ab95b5eb681d18053fe5b628fd5 /cloudinit
parent4445b881380a39a56490d8a8f9e07bba4540ec62 (diff)
downloadvyos-cloud-init-7f0871dc5b141ff4bf601b6d96021eba8a3bb0ec.tar.gz
vyos-cloud-init-7f0871dc5b141ff4bf601b6d96021eba8a3bb0ec.zip
write to 50-cloud-init.cfg and write systemd.link rules.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/distros/debian.py8
-rw-r--r--cloudinit/net/__init__.py48
2 files changed, 43 insertions, 13 deletions
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 909d6deb..b14fa3e2 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -46,7 +46,8 @@ APT_GET_WRAPPER = {
class Distro(distros.Distro):
hostname_conf_fn = "/etc/hostname"
locale_conf_fn = "/etc/default/locale"
- network_conf_fn = "/etc/network/interfaces"
+ network_conf_fn = "/etc/network/interfaces.d/50-cloud-init.cfg"
+ links_prefix = "/etc/systemd/network/50-cloud-init-"
def __init__(self, name, cfg, paths):
distros.Distro.__init__(self, name, cfg, paths)
@@ -79,7 +80,10 @@ class Distro(distros.Distro):
def _write_network_config(self, netconfig):
ns = net.parse_net_config_data(netconfig)
- net.render_network_state(network_state=ns, target="/")
+ net.render_network_state(target="/", network_state=ns,
+ eni=self.network_conf_fn,
+ links_prefix=self.links_prefix)
+ util.del_file("/etc/network/interfaces.d/eth0.cfg")
return []
def _bring_up_interfaces(self, device_names):
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index 63fad2fa..ae7b1c04 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -20,7 +20,6 @@ import errno
import glob
import os
import re
-import string
from cloudinit import log as logging
from cloudinit import util
@@ -30,6 +29,7 @@ from . import network_state
LOG = logging.getLogger(__name__)
SYS_CLASS_NET = "/sys/class/net/"
+LINKS_FNAME_PREFIX = "etc/systemd/network/50-cloud-init-"
NET_CONFIG_OPTIONS = [
"address", "netmask", "broadcast", "network", "metric", "gateway",
@@ -423,19 +423,45 @@ def render_interfaces(network_state):
return content
-def render_network_state(target, network_state):
- eni = 'etc/network/interfaces'
- netrules = 'etc/udev/rules.d/70-persistent-net.rules'
+def render_network_state(target, network_state, eni="etc/network/interfaces",
+ links_prefix=LINKS_FNAME_PREFIX,
+ netrules='etc/udev/rules.d/70-persistent-net.rules'):
- eni = os.path.sep.join((target, eni,))
- util.ensure_dir(os.path.dirname(eni))
- with open(eni, 'w+') as f:
+ fpeni = os.path.sep.join((target, eni,))
+ util.ensure_dir(os.path.dirname(fpeni))
+ with open(fpeni, 'w+') as f:
f.write(render_interfaces(network_state))
- netrules = os.path.sep.join((target, netrules,))
- util.ensure_dir(os.path.dirname(netrules))
- with open(netrules, 'w+') as f:
- f.write(render_persistent_net(network_state))
+ if netrules:
+ netrules = os.path.sep.join((target, netrules,))
+ util.ensure_dir(os.path.dirname(netrules))
+ with open(netrules, 'w+') as f:
+ f.write(render_persistent_net(network_state))
+
+ if links_prefix:
+ render_systemd_links(target, network_state, links_prefix)
+
+
+def render_systemd_links(target, network_state,
+ links_prefix=LINKS_FNAME_PREFIX):
+ fp_prefix = os.path.sep.join((target, links_prefix))
+ for f in glob.glob(fp_prefix + "*"):
+ os.unlink(f)
+
+ interfaces = network_state.get('interfaces')
+ for iface in interfaces.values():
+ if (iface['type'] == 'physical' and 'name' in iface and
+ 'mac_address' in iface):
+ fname = fp_prefix + iface['name'] + ".link"
+ with open(fname, "w") as fp:
+ fp.write("\n".join([
+ "[Match]",
+ "MACAddress=" + iface['mac_address'],
+ "",
+ "[Link]",
+ "Name=" + iface['name'],
+ ""
+ ]))
def is_disabled_cfg(cfg):