diff options
author | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-02-27 12:41:48 +0000 |
---|---|---|
committer | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-02-27 12:44:14 +0000 |
commit | f4c0ab971485f6f3c47596a22ed1dc95d58875ca (patch) | |
tree | 955ef7d9c0fbe8b29bfc69a288409d3e8bea8fa7 | |
parent | 8c3f1ae61de3628e6b33eba8918dec83ba88dd83 (diff) | |
download | morph-f4c0ab971485f6f3c47596a22ed1dc95d58875ca.tar.gz |
simple-network.configure: process pairs of parameters in a function
-rwxr-xr-x | morphlib/exts/simple-network.configure | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/morphlib/exts/simple-network.configure b/morphlib/exts/simple-network.configure index 1981dcda..a24c5845 100755 --- a/morphlib/exts/simple-network.configure +++ b/morphlib/exts/simple-network.configure @@ -69,11 +69,37 @@ class SimpleNetworkConfigurationExtension(cliapp.Application): return sum([bin(int(x)).count('1') for x in mask.split('.')]) + def process_pairs(self, pairs): + """Process rest of 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] + + if gateway is not None: + lines += ["Gateway=%s" % gateway] + + return lines + def generate_iface_file(self, stanza): """Generate an interfaces stanza from the provided data.""" name = stanza['name'] itype = stanza['type'] + pairs = stanza['args'].items() if itype == "loopback": return @@ -84,7 +110,7 @@ class SimpleNetworkConfigurationExtension(cliapp.Application): if itype == "dhcp": lines += ["DHCP=yes"] else: - lines += ["%s=%s" % elem for elem in stanza['args'].items()] + lines += self.process_pairs (pairs) return "\n".join(lines) |