Fetch ips of interfaces with dhcp enabled

Change-Id: Ifa8bcae524307e7f62c599db32c2a766e2c899b1
diff --git a/TestON/drivers/common/cli/hostdriver.py b/TestON/drivers/common/cli/hostdriver.py
index 6175801..8f3037e 100644
--- a/TestON/drivers/common/cli/hostdriver.py
+++ b/TestON/drivers/common/cli/hostdriver.py
@@ -56,6 +56,7 @@
             self.interfaces.append( { 'ips': [ self.options[ 'ip' ] ],
                                       'isUp': True,
                                       'mac': self.options[ 'mac' ],
+                                      'dhcp': self.options[ 'dhcp' ],
                                       'name': self.options.get( 'interfaceName', None ) } )
 
             try:
@@ -80,6 +81,15 @@
                 port=None,
                 pwd=self.pwd )
 
+            # Update IP of interfaces if using dhcp
+            for intf in self.interfaces:
+                if intf[ 'dhcp' ].lower() == "true":
+                    ip = self.getIPAddress( iface=intf[ 'name' ] )
+                    if ip:
+                        intf['ips'] = [ ip ]
+                    else:
+                        main.log.warn( self.name + ": Could not find IP of %s" % intf[ 'name' ] )
+
             if self.handle:
                 main.log.info( "Connection successful to the " +
                                self.user_name +
@@ -208,6 +218,26 @@
             main.log.error( self.name + ":     " + self.handle.before )
             return main.FALSE
 
+    def getIPAddress( self, iface=None, proto='IPV4' ):
+        """
+        Returns IP address of the host
+        """
+        cmd = "ifconfig %s" % iface if iface else ""
+        response = self.command( cmd )
+        pattern = ''
+        if proto == 'IPV4':
+            pattern = "inet\s(\d+\.\d+\.\d+\.\d+)\s\snetmask"
+        else:
+            pattern = "inet6\s([\w,:]*)/\d+\s\sprefixlen"
+        ipAddressSearch = re.search( pattern, response )
+        if not ipAddressSearch:
+            return None
+        main.log.info(
+            self.name +
+            ": IP-Address is " +
+            ipAddressSearch.group( 1 ) )
+        return ipAddressSearch.group( 1 )
+
     def ping( self, dst, ipv6=False, interface=None, wait=3 ):
         """
         Description: