Initial commit for phase 2, Add some simple validation.
[vpp.git] / extras / vpp_config / vpplib / VPPUtil.py
index 350b775..f042e80 100644 (file)
@@ -372,6 +372,45 @@ class VPPUtil(object):
                 for _, value in def_setting_tb_displayed.items():
                     self.exec_command('vppctl sh {}'.format(value))
 
+    @staticmethod
+    def get_int_ip(node):
+        """
+        Get the VPP interfaces and IP addresses
+
+        :param node: VPP node.
+        :type node: dict
+        :returns: Dictionary containing VPP interfaces and IP addresses
+        :rtype: dictionary
+        """
+        interfaces = {}
+        cmd = 'vppctl show int addr'
+        (ret, stdout, stderr) = VPPUtil.exec_command(cmd)
+        if ret != 0:
+            return interfaces
+
+        lines = stdout.split('\n')
+        if len(lines[0]) is not 0:
+            if lines[0].split(' ')[0] == 'FileNotFoundError':
+                return interfaces
+
+        for line in lines:
+            if len(line) is 0:
+                continue
+
+            # If the first character is not whitespace
+            # create a new interface
+            if len(re.findall(r'\s', line[0])) is 0:
+                spl = line.split()
+                name = spl[0]
+                if name == 'local0':
+                    continue
+                interfaces[name] = {}
+                interfaces[name]['state'] = spl[1].lstrip('(').rstrip('):\r')
+            else:
+                interfaces[name]['address'] = line.lstrip(' ').rstrip('\r')
+
+        return interfaces
+
     @staticmethod
     def get_hardware(node):
         """
@@ -380,7 +419,7 @@ class VPPUtil(object):
 
         :param node: VPP node.
         :type node: dict
-        :returns: Dictionary containing improtant VPP information
+        :returns: Dictionary containing VPP hardware information
         :rtype: dictionary
         """