import socket
import time


def waitForSSHAvailable(ipAddress, timeout=600):
    """
    Wait until SSH is available, that is its network interface is up

    :param ipAddress: ipAddress
    :type ipAddress: str
    :param timeout: timeout
    :type timeout: int
    :returns: whether SSH is available
    :rtype: bool
    """
    sshSocket = socket.socket()
    sshSocket.settimeout(1)
    start = time.time()
    end = start + timeout
    while time.time() < end:

        try:
            sshSocket.connect((ipAddress, 22))
            sshSocket.recv(256)
            sshSocket.close()
            break
        except socket.error:
            time.sleep(1)

    return time.time() <= end