Skip to content

Instantly share code, notes, and snippets.

@queertypes
Created February 14, 2014 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save queertypes/9006840 to your computer and use it in GitHub Desktop.
Save queertypes/9006840 to your computer and use it in GitHub Desktop.
Extract tenants from marconi installation
#!/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