def split_into_to_keep_to_delete()

in src/services/modular_helpers.py [0:0]


def split_into_to_keep_to_delete(payload: ResolveParentsPayload
                                 ) -> tuple[set[Parent], set[Parent]]:
    """
    It distributes the given parents list into two groups: parents that should
    be kept and parents that should be removed (based on provided params).
    After executing this method the payload will contain only those tenant
    names for which parents should be created
    Changes the payload in place
    :param payload:
    :return:
    """
    to_delete = set()
    to_keep = set()

    while payload.parents:
        parent = payload.parents.pop()
        if parent.scope == ParentScope.SPECIFIC and parent.tenant_name in payload.tenant_names:
            to_keep.add(parent)
            payload.tenant_names.remove(parent.tenant_name)
        elif parent.scope == ParentScope.DISABLED and parent.tenant_name in payload.exclude_tenants:
            to_keep.add(parent)
            payload.exclude_tenants.remove(parent.tenant_name)
        elif parent.scope == ParentScope.ALL and not parent.cloud and payload.all_tenants and not payload.clouds:
            to_keep.add(parent)
            payload.all_tenants = False
        elif parent.scope == ParentScope.ALL and parent.cloud in payload.clouds and payload.all_tenants:
            to_keep.add(parent)
            payload.clouds.remove(parent.cloud)
            if not payload.clouds:
                payload.all_tenants = False
        else:
            to_delete.add(parent)
    return to_keep, to_delete