Created
February 14, 2014 18:56
-
-
Save queertypes/9006840 to your computer and use it in GitHub Desktop.
Extract tenants from marconi installation
This file contains 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 | |
from __future__ import print_function | |
import sys | |
import pymongo | |
def connection(uri): | |
if uri and 'replicaSet' in uri: | |
MongoClient = pymongo.MongoReplicaSetClient | |
else: | |
MongoClient = pymongo.MongoClient | |
return MongoClient(uri) | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print('usage: {0} MONGO_URI'.format(sys.argv[0])) | |
quit() | |
uri = sys.argv[1] | |
conn = connection(uri) | |
cursor = conn.marconi.catalogue.find({}, {'p_q': 1, '_id': 0}) | |
projs = set([v['p_q'].split('/')[0] for v in cursor]) - set(['']) | |
print('Registered tenants: {0}'.format(len(projs))) | |
for tenant in sorted(projs): | |
print('- {0}'.format(tenant)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment