def configure_ilm_policy()

in src/es_pii_tool/helpers/utils.py [0:0]


def configure_ilm_policy(task: 'Task', data: 'DotMap') -> None:
    """
    Prune phases we've already passed.

    If only_expunge_deletes is True in the job config, set any force_merge_index
    actions to False.
    """
    # Copy the existing policy to a new spot
    data.new.ilmpolicy = data.ilm.lifecycle.policy

    # Prune phases from existing ILM policy we've already surpassed
    for phase in list(data.new.ilmpolicy.phases.toDict().keys()):
        if PHASES.index(data.ilm.explain.phase) > PHASES.index(phase):
            del data.new.ilmpolicy.phases[phase]

    # Figure out if we're doing force merge
    fmerge = True
    if 'forcemerge' in task.job.config:
        fmkwargs = task.job.config['forcemerge']
        if 'only_expunge_deletes' in fmkwargs and fmkwargs['only_expunge_deletes']:
            fmerge = False
    else:
        fmerge = False

    # Loop through the remaining phases and set 'force_merge_index': False
    # to the cold or frozen actions.

    for phase in data.new.ilmpolicy.phases:
        if phase not in ['cold', 'frozen']:
            continue
        if 'searchable_snapshot' in data.new.ilmpolicy.phases[phase].actions:
            data.new.ilmpolicy.phases[
                phase
            ].actions.searchable_snapshot.force_merge_index = fmerge