<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def __get_conn(**kwargs):
    '''
    Detects what type of dom this node is and attempts to connect to the
    correct hypervisor via libvirt.

    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    '''
    # This has only been tested on kvm and xen, it needs to be expanded to
    # support all vm layers supported by libvirt
    # Connection string works on bhyve, but auth is not tested.

    username = kwargs.get('username', None)
    password = kwargs.get('password', None)
    conn_str = kwargs.get('connection', None)
    if not conn_str:
        conn_str = __salt__['config.get']('virt.connect', None)
        if conn_str is not None:
            salt.utils.versions.warn_until(
                'Sodium',
                '\'virt.connect\' configuration property has been deprecated in favor '
                'of \'virt:connection:uri\'. \'virt.connect\' will stop being used in '
                '{version}.'
            )
        else:
            conn_str = __salt__['config.get']('libvirt:connection', None)
            if conn_str is not None:
                salt.utils.versions.warn_until(
                    'Sodium',
                    '\'libvirt.connection\' configuration property has been deprecated in favor '
                    'of \'virt:connection:uri\'. \'libvirt.connection\' will stop being used in '
                    '{version}.'
                )

        conn_str = __salt__['config.get']('virt:connection:uri', conn_str)

    hypervisor = __salt__['config.get']('libvirt:hypervisor', None)
    if hypervisor is not None:
        salt.utils.versions.warn_until(
            'Sodium',
            '\'libvirt.hypervisor\' configuration property has been deprecated. '
            'Rather use the \'virt:connection:uri\' to properly define the libvirt '
            'URI or alias of the host to connect to. \'libvirt:hypervisor\' will '
            'stop being used in {version}.'
        )

    if hypervisor == 'esxi' and conn_str is None:
        salt.utils.versions.warn_until(
            'Sodium',
            'esxi hypervisor default with no default connection URI detected, '
            'please set \'virt:connection:uri\' to \'esx\' for keep the legacy '
            'behavior. Will default to libvirt guess once \'libvirt:hypervisor\' '
            'configuration is removed in {version}.'
        )
        conn_str = 'esx'

    try:
        auth_types = [libvirt.VIR_CRED_AUTHNAME,
                      libvirt.VIR_CRED_NOECHOPROMPT,
                      libvirt.VIR_CRED_ECHOPROMPT,
                      libvirt.VIR_CRED_PASSPHRASE,
                      libvirt.VIR_CRED_EXTERNAL]
        conn = libvirt.openAuth(conn_str, [auth_types, __get_request_auth(username, password), None], 0)
    except Exception:
        raise CommandExecutionError(
            'Sorry, {0} failed to open a connection to the hypervisor '
            'software at {1}'.format(
                __grains__['fqdn'],
                conn_str
            )
        )
    return conn