src/lsi/lsi.py
def _connect_ssh(entry, username, idfile, tunnel=None):
    """
    SSH into to a host.

    :param entry: The host entry to pull the hostname from.
    :type entry: :py:class:`HostEntry`
    :param username: To use a specific username.
    :type username: ``str`` or ``NoneType``
    :param idfile: The SSH identity file to use, if supplying a username.
    :type idfile: ``str`` or ``NoneType``
    :param tunnel: Host to tunnel SSH command through.
    :type tunnel: ``str`` or ``NoneType``

    :return: An exit status code.
    :rtype: ``int``
    """
    if entry.hostname != "" and entry.hostname is not None:
        _host = entry.hostname
    elif entry.public_ip != "" and entry.public_ip is not None:
        _host = entry.public_ip
    elif entry.private_ip != "" and entry.private_ip is not None:
        if tunnel is None:
            raise ValueError("Entry does not have a hostname or public IP. "
                             "You can connect via private IP if you use a "
                             "tunnel.")
        _host = entry.private_ip
    else:
        raise ValueError("No hostname, public IP or private IP information "
                         "found on host entry. I don't know how to connect.")
    command = _build_ssh_command(_host, username, idfile, None, tunnel)
    print('Connecting to %s...' % cyan(entry.display()))
    print('SSH command: %s' % green(command))
    proc = subprocess.Popen(command, shell=True)
    return proc.wait()
def _connect_ssh(entry, username, idfile, tunnel=None):
    """
    SSH into to a host.

    :param entry: The host entry to pull the hostname from.
    :type entry: :py:class:`HostEntry`
    :param username: To use a specific username.
    :type username: ``str`` or ``NoneType``
    :param idfile: The SSH identity file to use, if supplying a username.
    :type idfile: ``str`` or ``NoneType``
    :param tunnel: Host to tunnel SSH command through.
    :type tunnel: ``str`` or ``NoneType``

    :return: An exit status code.
    :rtype: ``int``
    """
    if entry.hostname != "" and entry.hostname is not None:
        _host = entry.hostname
    elif entry.public_ip != "" and entry.public_ip is not None:
        _host = entry.public_ip
    elif entry.private_ip != "" and entry.private_ip is not None:
        if tunnel is None:
            raise ValueError("Entry does not have a hostname or public IP. "
                             "You can connect via private IP if you use a "
                             "tunnel.")
        _host = entry.private_ip
    else:
        raise ValueError("No hostname, public IP or private IP information "
                         "found on host entry. I don't know how to connect.")
    command = _build_ssh_command(_host, username, idfile, None, tunnel)
    print('Connecting to %s...' % cyan(entry.display()))
    print('SSH command: %s' % green(command))
    proc = subprocess.Popen(command, shell=True)
    return proc.wait()
SSH into to a host.

    :param entry: The host entry to pull the hostname from.
    :type entry: :py:class:`HostEntry`
    :param username: To use a specific username.
    :type username: ``str`` or ``NoneType``
    :param idfile: The SSH identity file to use, if supplying a username.
    :type idfile: ``str`` or ``NoneType``
    :param tunnel: Host to tunnel SSH command through.
    :type tunnel: ``str`` or ``NoneType``

    :return: An exit status code.
    :rtype: ``int``