sys.exit(2) # initialize it replSetConfig = { "_id" : "xxx", "members" : [ {"_id" : 0, "host" : "mongo_D1", "priority" : 10}, {"_id" : 1, "host" : "mongo_D2"} ] } print("Init replica set..") client = MongoClient('mongo_D1', 27017) client.admin.command('replSetInitiate', replSetConfig) wait_to_become_primary('mongo_D1', 27017) print("Sharding the collection..") client = MongoClient('mongo_S1', 27017, read_preference=ReadPreference.PRIMARY_PREFERRED) client.admin.command('addShard', 'xxx/mongo_D1') client.admin.command('enableSharding', 'test') client.admin.command('shardCollection', 'test.test', key={'_id': 1}) client.admin.command('setParameter', 1, logLevel=5) print("Napping just in case...") time.sleep(5) client['test'].test.insert(deploy) client.admin.command('flushRouterConfig', 1) #for x in range(0, 5):
"members": [{ "_id": 0, "host": "mongo_D1", "priority": 10 }, { "_id": 1, "host": "mongo_D2" }] } print("Init replica set..") client = MongoClient('mongo_D1', 27017) client.admin.command('replSetInitiate', replSetConfig) # we can use this fancy function to wait until the host becomes primary wait_to_become_primary('mongo_D1', 27017) print("Sharding the collection..") client = MongoClient('mongo_S1', 27017, read_preference=ReadPreference.PRIMARY_PREFERRED) client.admin.command('addShard', 'xxx/mongo_D1') client.admin.command('enableSharding', 'test') client.admin.command('shardCollection', 'test.test', key={'_id': 1}) client.admin.command('setParameter', 1, logLevel=5) # TEST TIME! print("Napping just in case...") time.sleep(5)
if res != 1: print ("Failed deploying. Aborting") docker.cleanup() sys.exit(2) # initialize it replSetConfig = { "_id": "xxx", "members": [{"_id": 0, "host": "mongo_D1", "priority": 10}, {"_id": 1, "host": "mongo_D2"}], } print ("Init replica set..") client = MongoClient("mongo_D1", 27017) client.admin.command("replSetInitiate", replSetConfig) wait_to_become_primary("mongo_D1", 27017) print ("Sharding the collection..") client = MongoClient("mongo_S1", 27017, read_preference=ReadPreference.PRIMARY_PREFERRED) client.admin.command("addShard", "xxx/mongo_D1") client.admin.command("enableSharding", "test") client.admin.command("shardCollection", "test.test", key={"_id": 1}) client.admin.command("setParameter", 1, logLevel=5) print ("Napping just in case...") time.sleep(5) client["test"].test.insert(deploy) client.admin.command("flushRouterConfig", 1)