Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tarsisazevedo/814e90a01c6e84db6c82 to your computer and use it in GitHub Desktop.
Save tarsisazevedo/814e90a01c6e84db6c82 to your computer and use it in GitHub Desktop.
Migrate tsuru containers to new structure
import os
import redis
from pymongo import MongoClient
mongo_host = os.getenv("MONGO_HOST", "localhost")
mongo_port = os.getenv("MONGO_PORT", "27017")
mongo_client = MongoClient(mongo_host, int(mongo_port))
redis_host = os.getenv("REDIS_HOST", "localhost")
redis_port = os.getenv("REDIS_PORT", "6379")
r = redis.StrictRedis(host=redis_host, port=int(redis_port))
redis_key = "docker-cluster:%s" # tsuru.conf: scheduler-prefix
redis_value = "http://%s:4243"
containers = mongo_client.tsuru["docker-containers"].find()
for container in containers:
r.set(redis_key % container["id"], redis_value % container["hostaddr"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment