From 96f0adabfde9c624db30e962b8aad3f066c44377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Fri, 6 Mar 2015 12:39:58 +0000 Subject: simple-network.configure: Generate networkd .network files as well --- morphlib/exts/simple-network.configure | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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. -- cgit v1.2.1