New network lib file and minor fixes
Changes:
- Function to return netmask prefix length.
- Verify the prefix length.
Verified : Python 2.7 and 3.4
Tested : Master build.
Change-Id: I46d12acbadeb913f4aa7e164940c2f517d8acdb9
Signed-off-by: Prashanth Katti <prkatti1@in.ibm.com>
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/bmc_network_utils.py b/lib/bmc_network_utils.py
new file mode 100644
index 0000000..530f80f
--- /dev/null
+++ b/lib/bmc_network_utils.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+r"""
+Network generic functions.
+
+"""
+
+import ipaddress
+from robot.libraries.BuiltIn import BuiltIn
+
+
+def netmask_prefix_length(netmask):
+ r"""
+ Return the netmask prefix length.
+
+ Description of argument(s):
+ netmask Netmask value (e.g. "255.255.0.0", "255.255.255.0",
+ "255.252.0.0", etc.).
+ """
+
+ # IP address netmask format: '0.0.0.0/255.255.252.0'
+ return ipaddress.ip_network('0.0.0.0/' + netmask).prefixlen