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,
    }))