diff options
author | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-02-27 12:41:44 +0000 |
---|---|---|
committer | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-02-27 12:44:14 +0000 |
commit | 8c3f1ae61de3628e6b33eba8918dec83ba88dd83 (patch) | |
tree | 68f08f048950234ae4663d1ddfe8b4a433e61afc | |
parent | 5ef1a28c82871c8500bdc1bb30ce415749c84c83 (diff) | |
download | morph-8c3f1ae61de3628e6b33eba8918dec83ba88dd83.tar.gz |
simple-network.configure: Add function to convert mask to cidr suffix
255.255.255.0 -> 24
-rwxr-xr-x | morphlib/exts/simple-network.configure | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/morphlib/exts/simple-network.configure b/morphlib/exts/simple-network.configure index 258bf7a1..1981dcda 100755 --- a/morphlib/exts/simple-network.configure +++ b/morphlib/exts/simple-network.configure @@ -62,6 +62,13 @@ class SimpleNetworkConfigurationExtension(cliapp.Application): with open(path, "w") as f: f.write(iface_file) + def convert_net_mask_to_cidr_suffix(self, mask): + """Convert dotted decimal form (255.255.255.0) of a subnet mask to CIDR + suffix notation (24) + """ + + return sum([bin(int(x)).count('1') for x in mask.split('.')]) + def generate_iface_file(self, stanza): """Generate an interfaces stanza from the provided data.""" |