diff options
-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 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. |