summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2015-03-06 12:39:58 +0000
committerJavier Jardón <javier.jardon@codethink.co.uk>2015-03-16 17:59:54 +0000
commit96f0adabfde9c624db30e962b8aad3f066c44377 (patch)
treede6620d86a4392c3d7ac8b0e8a28288987818b00
parent62c947594635cc0edffa2ac4826641d8df33ae28 (diff)
downloadmorph-96f0adabfde9c624db30e962b8aad3f066c44377.tar.gz
simple-network.configure: Generate networkd .network files as well
-rwxr-xr-xmorphlib/exts/simple-network.configure33
1 files changed, 33 insertions, 0 deletions
diff --git a/morphlib/exts/simple-network.configure b/morphlib/exts/simple-network.configure
index c533ff22..5b02142c 100755
--- a/morphlib/exts/simple-network.configure
+++ b/morphlib/exts/simple-network.configure
@@ -50,6 +50,7 @@ class SimpleNetworkConfigurationExtension(cliapp.Application):
stanzas = self.parse_network_stanzas(network_config)
self.generate_interfaces_file(args, stanzas)
+ self.generate_networkd_files(args, stanzas)
def generate_interfaces_file(self, args, stanzas):
"""Generate /etc/network/interfaces file"""
@@ -87,6 +88,38 @@ class SimpleNetworkConfigurationExtension(cliapp.Application):
lines += [""]
return "\n".join(lines)
+ def generate_networkd_files(self, args, stanzas):
+ """Generate .network files"""
+
+ for i, stanza in enumerate(stanzas, 50):
+ iface_file = self.generate_networkd_file(stanza)
+
+ if iface_file is None:
+ continue
+
+ path = os.path.join(args[0], "etc", "systemd", "network",
+ "%s-%s.network" % (i, stanza['name']))
+
+ with open(path, "w") as f:
+ f.write(iface_file)
+
+ def generate_networkd_file(self, stanza):
+ """Generate an .network file from the provided data."""
+
+ name = stanza['name']
+ itype = stanza['type']
+ pairs = stanza['args'].items()
+
+ if itype == "loopback":
+ return
+
+ lines = ["[Match]"]
+ lines += ["Name=%s\n" % name]
+ lines += ["[Network]"]
+ if itype == "dhcp":
+ lines += ["DHCP=yes"]
+
+ return "\n".join(lines)
def parse_network_stanzas(self, config):
"""Parse a network config environment variable into stanzas.