def get_cached_snapshot_images(cluster):
    """Get the cached snapshot images for a specific cluster.

    Return all of the non-expired snapshot images for a specific
    cluster by checking all build plans to see which plans the cluster
    is associated with and grabbing snapshot images for any unexpired
    image associated with those plans.
    """
    now = get_current_datetime()
    plan_ids = [plan.id for plan in get_plans_for_cluster(cluster)]

    # Although performance isn't critical here, this shuts up a warning
    # from sqlalchemy
    if not plan_ids:
        return []

    return db.session.query(SnapshotImage).filter(
        sqlalchemy.or_(
            CachedSnapshotImage.expiration_date == None,  # NOQA
            now <= CachedSnapshotImage.expiration_date,
        ),
        CachedSnapshotImage.id == SnapshotImage.id,
        SnapshotImage.plan_id.in_(plan_ids)
    ).all()
dataset/ETHPy150Open dropbox/changes/changes/lib/snapshot_garbage_collection.py/get_cached_snapshot_images/original