def __is_custom_ou_valid()

in ad-joining/register-computer/main.py [0:0]


def __is_custom_ou_valid(ad_connection, custom_ou_dn):
    try:
        matches = ad_connection.find_ou(custom_ou_dn, includeDescendants=False)
        if len(matches) == 0:
            logging.info("No OU with name '%s' found in directory" % custom_ou_dn)
        elif len(matches) > 1:
            logging.info("Found multiple OUs with name '%s' in directory" % custom_ou_dn)
        else:
            return True
    except Exception as e:
        logging.exception("Looking up OU '%s' in Active Directory failed: '%s'" % (custom_ou_dn, str(e)))
        raise

    return False