summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2015-02-27 12:41:44 +0000
committerJavier Jardón <javier.jardon@codethink.co.uk>2015-02-27 12:44:14 +0000
commit8c3f1ae61de3628e6b33eba8918dec83ba88dd83 (patch)
tree68f08f048950234ae4663d1ddfe8b4a433e61afc
parent5ef1a28c82871c8500bdc1bb30ce415749c84c83 (diff)
downloadmorph-8c3f1ae61de3628e6b33eba8918dec83ba88dd83.tar.gz
simple-network.configure: Add function to convert mask to cidr suffix
255.255.255.0 -> 24
-rwxr-xr-xmorphlib/exts/simple-network.configure7
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."""