def METHOD_NAME(session_multihost, request):
    """ Join to AD using net ads command """
    ad_realm = session_multihost.ad[0].realm
    ad_ip = session_multihost.ad[0].ip
    ad_host = session_multihost.ad[0].sys_hostname
    client_ad = sssdTools(session_multihost.client[0], session_multihost.ad[0])
    client_ad.update_resolv_conf(session_multihost.ad[0])
    client_ad.update_resolv_conf(session_multihost.ad[len(session_multihost.ad)-1])
    client_ad.systemsssdauth(ad_realm, ad_host)
    client_ad.disjoin_ad(raiseonerr=False)  # Make sure system is disjoined from AD
    client_ad.create_kdcinfo(ad_realm, ad_ip)
    kinit = f'kinit Administrator@{ad_realm}'
    ad_password = session_multihost.ad[0].ssh_password
    try:
        session_multihost.client[0].run_command(kinit, stdin_text=ad_password)
    except subprocess.CalledProcessError:
        pytest.fail("kinit failed")
    def _join(membersw=None):
        """ Join AD """
        if membersw == 'samba':
            client_ad.join_ad(ad_realm, ad_password, mem_sw='samba')
        else:
            client_ad.join_ad(ad_realm, ad_password)
    def adleave():
        """ Disjoin AD """
        client_ad.disjoin_ad(raiseonerr=False)
        remove_keytab = 'rm -f /etc/krb5.keytab'
        kdestroy_cmd = 'kdestroy -A'
        session_multihost.client[0].run_command(kdestroy_cmd)
        session_multihost.client[0].run_command(remove_keytab)
    request.addfinalizer(adleave)
    return _join