summaryrefslogtreecommitdiff
path: root/morphlib/exts/simple-network.configure
diff options
context:
space:
mode:
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.