diff options
author | selias <samelias@cisco.com> | 2016-05-11 11:42:54 +0200 |
---|---|---|
committer | Matej Klotton <mklotton@cisco.com> | 2016-05-12 07:33:43 +0000 |
commit | 481744b2732ab840a00129bacb5994baa19e125c (patch) | |
tree | 54f8e6f8435a1fa5bfc743a86741cc5da9e736af /resources/libraries/python/IPUtil.py | |
parent | f48d2c859e6dd4d03e28db45d60beb182664ab16 (diff) |
Update Honeycomb interface IPv4 test
- add verification of ipv4 subnet prefix support
- modify keywords to allow setting ipv4 address with network prefix
- fix variable definitions to evaluate numbers as ints, not strings
- add exception to ipv4 netmask/prefix conversion method
Change-Id: I9343ceb35856ddb33674d7067f1def6d40e99acc
Signed-off-by: selias <samelias@cisco.com>
Diffstat (limited to 'resources/libraries/python/IPUtil.py')
-rw-r--r-- | resources/libraries/python/IPUtil.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/resources/libraries/python/IPUtil.py b/resources/libraries/python/IPUtil.py index 00a7000c65..4b6e2766d8 100644 --- a/resources/libraries/python/IPUtil.py +++ b/resources/libraries/python/IPUtil.py @@ -43,19 +43,22 @@ class IPUtil(object): dev=interface, ip=addr, h=node['host'])) -def convert_ipv4_netmask_prefix(netmask): +def convert_ipv4_netmask_prefix(network): """Convert network mask to equivalent network prefix length or vice versa. Example: mask 255.255.0.0 -> prefix length 16 - :param netmask: network mask or network prefix length. - :type netmask: str or int - :return: network mask or network prefix length. + :param network: Network mask or network prefix length. + :type network: str or int + :return: Network mask or network prefix length. :rtype: str or int """ temp_address = "0.0.0.0" - net = IPv4Network(u"{0}/{1}".format(temp_address, netmask), False) + net = IPv4Network(u"{0}/{1}".format(temp_address, network), False) - if isinstance(netmask, int): + if isinstance(network, int) and (0 < network < 33): return net.netmask - elif isinstance(netmask, basestring): + elif isinstance(network, basestring): return net.prefixlen + else: + raise Exception("Value {0} is not a valid ipv4 netmask or network" + " prefix length".format(network)) |