def connect(<EOL>self,<EOL>hostkey=None,<EOL>username="<STR_LIT>",<EOL>password=None,<EOL>pkey=None,<EOL>gss_host=None,<EOL>gss_auth=False,<EOL>gss_kex=False,<EOL>gss_deleg_creds=True,<EOL>gss_trust_dns=True,<EOL>):
if hostkey is not None:<EOL><INDENT>self._preferred_keys = [hostkey.get_name()]<EOL><DEDENT>self.set_gss_host(<EOL>gss_host=gss_host,<EOL>trust_dns=gss_trust_dns,<EOL>gssapi_requested=gss_kex or gss_auth,<EOL>)<EOL>self.start_client()<EOL>if (hostkey is not None) and not gss_kex:<EOL><INDENT>key = self.get_remote_server_key()<EOL>if (<EOL>key.get_name() != hostkey.get_name()<EOL>or key.asbytes() != hostkey.asbytes()<EOL>):<EOL><INDENT>self._log(DEBUG, "<STR_LIT>")<EOL>self._log(<EOL>DEBUG,<EOL>"<STR_LIT>".format(<EOL>hostkey.get_name(), repr(hostkey.asbytes())<EOL>),<EOL>)<EOL>self._log(<EOL>DEBUG,<EOL>"<STR_LIT>".format(<EOL>key.get_name(), repr(key.asbytes())<EOL>),<EOL>)<EOL>raise SSHException("<STR_LIT>")<EOL><DEDENT>self._log(<EOL>DEBUG, "<STR_LIT>".format(hostkey.get_name())<EOL>)<EOL><DEDENT>if (pkey is not None) or (password is not None) or gss_auth or gss_kex:<EOL><INDENT>if gss_auth:<EOL><INDENT>self._log(<EOL>DEBUG, "<STR_LIT>"<EOL>)  <EOL>self.auth_gssapi_with_mic(<EOL>username, self.gss_host, gss_deleg_creds<EOL>)<EOL><DEDENT>elif gss_kex:<EOL><INDENT>self._log(DEBUG, "<STR_LIT>")<EOL>self.auth_gssapi_keyex(username)<EOL><DEDENT>elif pkey is not None:<EOL><INDENT>self._log(DEBUG, "<STR_LIT>")<EOL>self.auth_publickey(username, pkey)<EOL><DEDENT>else:<EOL><INDENT>self._log(DEBUG, "<STR_LIT>")<EOL>self.auth_password(username, password)<EOL><DEDENT><DEDENT>return<EOL>
Negotiate an SSH2 session, and optionally verify the server's host key
and authenticate using a password or private key.  This is a shortcut
for `start_client`, `get_remote_server_key`, and
`Transport.auth_password` or `Transport.auth_publickey`.  Use those
methods if you want more control.

You can use this method immediately after creating a Transport to
negotiate encryption with a server.  If it fails, an exception will be
thrown.  On success, the method will return cleanly, and an encrypted
session exists.  You may immediately call `open_channel` or
`open_session` to get a `.Channel` object, which is used for data
transfer.

.. note::
    If you fail to supply a password or private key, this method may
    succeed, but a subsequent `open_channel` or `open_session` call may
    fail because you haven't authenticated yet.

:param .PKey hostkey:
    the host key expected from the server, or ``None`` if you don't
    want to do host key verification.
:param str username: the username to authenticate as.
:param str password:
    a password to use for authentication, if you want to use password
    authentication; otherwise ``None``.
:param .PKey pkey:
    a private key to use for authentication, if you want to use private
    key authentication; otherwise ``None``.
:param str gss_host:
    The target's name in the kerberos database. Default: hostname
:param bool gss_auth:
    ``True`` if you want to use GSS-API authentication.
:param bool gss_kex:
    Perform GSS-API Key Exchange and user authentication.
:param bool gss_deleg_creds:
    Whether to delegate GSS-API client credentials.
:param gss_trust_dns:
    Indicates whether or not the DNS is trusted to securely
    canonicalize the name of the host being connected to (default
    ``True``).

:raises: `.SSHException` -- if the SSH2 negotiation fails, the host key
    supplied by the server is incorrect, or authentication fails.

.. versionchanged:: 2.3
    Added the ``gss_trust_dns`` argument.