1#!/usr/bin/env python
2
3r"""
4Network generic functions.
5
6"""
7
8import ipaddress
9from robot.libraries.BuiltIn import BuiltIn
10
11
12def netmask_prefix_length(netmask):
13    r"""
14    Return the netmask prefix length.
15
16    Description of argument(s):
17    netmask     Netmask value (e.g. "255.255.0.0", "255.255.255.0",
18                                    "255.252.0.0", etc.).
19    """
20
21    # IP address netmask format: '0.0.0.0/255.255.252.0'
22    return ipaddress.ip_network('0.0.0.0/' + netmask).prefixlen
23