summaryrefslogtreecommitdiff
path: root/morphlib/exts/simple-network.configure
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2015-03-06 12:56:19 +0000
committerJavier Jardón <javier.jardon@codethink.co.uk>2015-03-16 17:59:54 +0000
commit952624c0a37e510851f8b983c60e7f6e2037e151 (patch)
tree20b8086dd844a319ea8363c7927417d555f4a6b7 /morphlib/exts/simple-network.configure
parent96f0adabfde9c624db30e962b8aad3f066c44377 (diff)
downloadmorph-952624c0a37e510851f8b983c60e7f6e2037e151.tar.gz
simple-network.configure: Add function to convert mask to cidr suffix
255.255.255.0 -> 24
Diffstat (limited to 'morphlib/exts/simple-network.configure')
-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 5b02142c..0e514e0b 100755
--- a/morphlib/exts/simple-network.configure
+++ b/morphlib/exts/simple-network.configure
@@ -121,6 +121,13 @@ class SimpleNetworkConfigurationExtension(cliapp.Application):
return "\n".join(lines)
+ def convert_net_mask_to_cidr_suffix(self, mask):
+ """Convert dotted decimal form of a subnet mask to CIDR suffix notation
+
+ For example: 255.255.255.0 -> 24
+ """
+ return sum(bin(int(x)).count('1') for x in mask.split('.'))
+
def parse_network_stanzas(self, config):
"""Parse a network config environment variable into stanzas.