Merge pull request #1502 from coreos-inc/image-replication

Enable storage replication for V2 and add backfill tool
This commit is contained in:
josephschorr 2016-06-02 15:02:53 -04:00
commit cad8746f9d
6 changed files with 93 additions and 12 deletions

View file

@ -0,0 +1,30 @@
import logging
import features
from endpoints.replication import queue_storage_replication
from data.database import Image, ImageStorage, Repository, User
def backfill_replication():
encountered = set()
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
print "Enqueueing image storage %s to be replicated" % (image.storage.uuid)
encountered.add(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()

View file

@ -0,0 +1,14 @@
import features
import json
from data import model
from app import image_replication_queue
def queue_storage_replication(namespace, storage):
""" Queues replication for the given image storage under the given namespace (if enabled). """
if features.STORAGE_REPLICATION:
namespace_user = model.user.get_namespace_user(namespace)
image_replication_queue.put([storage.uuid], json.dumps({
'namespace_user_id': namespace_user.id,
'storage_id': storage.uuid,
}))