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
commite36de9eb1129db24b47dfa84cd96c5e2e2e6a327 (patch)
tree6e64d96ab743f363a05431f57cb8cc80e40991cf
parentf1dce77123a814527f96d415b69ee10a06b8d36c (diff)
downloaddefinitions-e36de9eb1129db24b47dfa84cd96c5e2e2e6a327.tar.gz
simple-network.configure: Generate networkd .network files as well
-rwxr-xr-xsimple-network.configure33
1 files changed, 33 insertions, 0 deletions
diff --git a/simple-network.configure b/simple-network.configure
index c533ff22..5b02142c 100755
--- a/simple-network.configure
+++ b/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.