This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/util/backfillreplication.py

41 lines
1.3 KiB
Python
Raw Normal View History

import logging
import features
from app import storage, image_replication_queue
from data.database import Image, ImageStorage, Repository, User
from data import model
2016-06-08 19:55:29 +00:00
from util.registry.replication import queue_storage_replication
def backfill_replication():
encountered = set()
2016-06-08 19:55:47 +00:00
query = (Image
.select(Image, ImageStorage, Repository, User)
.join(ImageStorage)
.switch(Image)
.join(Repository)
.join(User))
for image in query:
if image.storage.uuid in encountered:
continue
namespace = image.repository.namespace_user.username
locations = model.user.get_region_locations(namespace)
locations_required = locations | set(storage.default_locations)
locations_missing = locations_required - set(image.storage.locations)
if locations_missing:
print "Enqueueing image storage %s to be replicated" % (image.storage.uuid)
encountered.add(image.storage.uuid)
if not image_replication_queue.alive([image.storage.uuid]):
queue_storage_replication(image.repository.namespace_user.username, image.storage)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
if not features.STORAGE_REPLICATION:
print "Storage replication is not enabled"
else:
backfill_replication()