From 952624c0a37e510851f8b983c60e7f6e2037e151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Fri, 6 Mar 2015 12:56:19 +0000 Subject: simple-network.configure: Add function to convert mask to cidr suffix 255.255.255.0 -> 24 --- morphlib/exts/simple-network.configure | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'morphlib/exts/simple-network.configure') 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. -- cgit v1.2.1