diff options
author | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-03-06 12:55:01 +0000 |
---|---|---|
committer | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-03-16 17:59:54 +0000 |
commit | 993a41a841ab2758f3941a2b1fbea262cae924a0 (patch) | |
tree | fdd16bfa0246da04c007d1061d283a26b7b4e684 /morphlib/exts | |
parent | 952624c0a37e510851f8b983c60e7f6e2037e151 (diff) | |
download | morph-993a41a841ab2758f3941a2b1fbea262cae924a0.tar.gz |
simple-network.configure: process pairs of parameters in a function
Diffstat (limited to 'morphlib/exts')
-rwxr-xr-x | morphlib/exts/simple-network.configure | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/morphlib/exts/simple-network.configure b/morphlib/exts/simple-network.configure index 0e514e0b..a058cba7 100755 --- a/morphlib/exts/simple-network.configure +++ b/morphlib/exts/simple-network.configure @@ -118,9 +118,38 @@ class SimpleNetworkConfigurationExtension(cliapp.Application): lines += ["[Network]"] if itype == "dhcp": lines += ["DHCP=yes"] + else: + lines += self.generate_networkd_entries(pairs) return "\n".join(lines) + def generate_networkd_entries(self, pairs): + """Generate networkd configuration entries with the other parameters""" + + address = None + netmask = None + gateway = None + lines = [] + for pair in pairs: + if pair[0] == 'address': + address = pair[1] + elif pair[0] == 'netmask': + netmask = pair[1] + elif pair[0] == 'gateway': + gateway = pair[1] + + if address and netmask: + network_suffix = self.convert_net_mask_to_cidr_suffix (netmask); + address_line = address + '/' + str(network_suffix) + lines += ["Address=%s" % address_line] + elif address or netmask: + raise Exception('address and netmask must be specified together') + + if gateway is not None: + lines += ["Gateway=%s" % gateway] + + return lines + def convert_net_mask_to_cidr_suffix(self, mask): """Convert dotted decimal form of a subnet mask to CIDR suffix notation |