def _handle_yaml(user_data):
    """ Process user data in YAML format"""
    log.info("Handling user data in YAML format.")
    ud = _load_user_data(user_data)
    # Handle bad user data as a string
    if ud == user_data:
        return _handle_empty()
    # Allow password based logins. Do so also in case only NX is being setup.
    if "freenxpass" in ud or "password" in ud:
        passwd = ud.get("freenxpass", None) or ud.get("password", None)
        _allow_password_logins(passwd)
    # Handle freenx passwords and the case with only a NX password sent
    if "freenxpass" in ud:
        _handle_freenx(ud["freenxpass"])
        if len(ud) == 1:
            return _handle_empty()
    # Create a YAML file from user data and store it as USER_DATA_FILE
    # This code simply ensures fields required by CloudMan are in the
    # created file. Any other fields that might be included as user data
    # are also included in the created USER_DATA_FILE
    if ud.get('no_start', None) is not None:
        log.info("Received 'no_start' user data option. Not doing anything else.")
        return
    if not ud.has_key('cluster_name'):
        log.warning("The provided user data should contain cluster_name field.")
        ud['cluster_name'] = 'aCloudManCluster_%s' % random.randrange(1, 9999999)
    elif ud['cluster_name'] == '':
        log.warning("The cluster_name field of user data should not be empty.")
        ud['cluster_name'] = random.randrange(1, 9999999) % 'aCloudManCluster_%s'

    if not ud.has_key('access_key'):
        log.info("The provided user data does not contain access_key field; setting it to None..")
        ud['access_key'] = None
    elif ud['access_key'] == '' or ud['access_key'] is None:
        log.warning("The access_key field of user data should not be empty; setting it to None.")
        ud['access_key'] = None

    if not ud.has_key('secret_key'):
        log.info("The provided user data does not contain secret_key field; setting it to None.")
        ud['secret_key'] = None
    elif ud['secret_key'] == '' or ud['secret_key'] is None:
        log.warning("The secret_key field of user data should not be empty; setting it to None.")
        ud['secret_key'] = None

    if not ud.has_key('password'):
        log.warning("The provided user data should contain password field.")
    elif ud['password'] == '':
        log.warning("The password field of user data should not be empty.")
    else: # ensure the password is a string
        ud['password'] = str(ud['password'])

    if not ud.has_key('bucket_default'):
        log.debug("The provided user data does not contain bucket_default field; setting it to '%s'."
            % DEFAULT_BUCKET_NAME)
        ud['bucket_default'] = DEFAULT_BUCKET_NAME
    elif ud['bucket_default'] == '':
        log.warning("The bucket_default field of user data was empty; setting it to '%s'."
            % DEFAULT_BUCKET_NAME)
        ud['bucket_default'] = DEFAULT_BUCKET_NAME

    if not ud.has_key('bucket_cluster'):
        if ud['access_key'] is not None and ud['secret_key'] is not None:
            ud['bucket_cluster'] = _get_bucket_name(ud['cluster_name'], ud['access_key'])

    if not ud.has_key('role'):
        ud['role'] = 'master'

    if not ud.has_key('cloudman_home'):
        ud['cloudman_home'] = CLOUDMAN_HOME

    if not ud.has_key('boot_script_name'):
        ud['boot_script_name'] = DEFAULT_BOOT_SCRIPT_NAME
    ud['boot_script_path'] = LOCAL_PATH # Marks where boot script was saved

    log.debug("Composed user data: %s" % ud)
    with open(USER_DATA_FILE, 'w') as ud_yaml:
        yaml.dump(ud, ud_yaml, default_flow_style=False)

    # Get & run boot script
    if _get_boot_script(ud):
        _run_boot_script(DEFAULT_BOOT_SCRIPT_NAME)

# ====================== Driver code ======================
dataset/ETHPy150Open chapmanb/cloudbiolinux/installed_files/ec2autorun.py/_handle_yaml/swapped operands of `%`