Created
June 9, 2014 09:19
-
-
Save a4180p/316ba465da60518ece5b to your computer and use it in GitHub Desktop.
creating dockers + mongo replicaset using python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # Author: A. Ponimaskin | |
| from __future__ import unicode_literals, absolute_import, print_function | |
| from pymongo import MongoClient | |
| import docker | |
| from six.moves import range | |
| import argparse | |
| from time import sleep | |
| import shutil | |
| import os | |
| argparser = argparse.ArgumentParser() | |
| argparser.add_argument("dir") | |
| args = argparser.parse_args() | |
| c = docker.Client() | |
| image_name = "ponimas/ffmpeg" | |
| rs = "transreplica" | |
| addrs = [] | |
| for i in range(1, 5): | |
| _dbdir = "%s/devenvs/n%s/db" % (args.dir, i) | |
| shutil.rmtree(_dbdir) | |
| os.mkdir(_dbdir) | |
| c.create_container( | |
| image_name, command="supervisord", | |
| name="dev%s" % i, | |
| volumes=["/data", "/data/playground"]) | |
| c.start("dev%s" % i, | |
| binds={ | |
| "%s/devenvs/n%s" % (args.dir, i): "/data", | |
| "%s/playground" % args.dir: "/data/playground"}) | |
| info = c.inspect_container("dev%s" % i) | |
| addrs.append(info["NetworkSettings"]["IPAddress"]) | |
| print(addrs) | |
| rscfg = {"_id": rs, "members": []} | |
| for i, addr in enumerate(addrs): | |
| rscfg["members"].append({ | |
| "host": "%s:27017" % addr, | |
| "_id": i}) | |
| sleep(5) | |
| connection = MongoClient(addrs[0], 27017) | |
| connection.admin.command("replSetInitiate", rscfg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment