Last active
August 29, 2015 14:17
-
-
Save abutcher/92d93990acca464c075a to your computer and use it in GitHub Desktop.
Recreate ose dns entries
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 | |
| import argparse | |
| from pymongo import MongoClient | |
| import urllib | |
| def main(): | |
| parser = argparse.ArgumentParser(description='Restore your OSE DNS entries.') | |
| parser.add_argument('--database-host', dest='dbhost', action='store', | |
| default='localhost', | |
| help='The primary database host to connect to.') | |
| parser.add_argument('--database-name', dest='dbname', action='store', | |
| required=True, | |
| help='Database name.') | |
| parser.add_argument('--database-user', dest='dbuser', action='store', | |
| required=True, | |
| help='Database user.') | |
| parser.add_argument('--database-password', dest='dbpasswd', action='store', | |
| required=True, | |
| help='Database password.') | |
| parser.add_argument('--database-port', dest='dbport', action='store', | |
| default='27017', | |
| help='Database port.') | |
| args = parser.parse_args() | |
| password = urllib.quote_plus(args.dbpasswd) | |
| uri = 'mongodb://' + args.dbuser + ':' + password + '@' + args.dbhost + ':' + args.dbport + '/' + args.dbname | |
| client = MongoClient(uri) | |
| db = client[args.dbname] | |
| for application in db.applications.find({}, {'name': 1, 'gears': 1, 'domain_namespace': 1, 'scalable': 1}): | |
| if application['scalable']: | |
| for gear in application['gears']: | |
| if 'port_interfaces' in gear.keys(): | |
| for interface in gear['port_interfaces']: | |
| if 'database' in interface['type']: | |
| print "%s-%s\tCNAME\t%s" % (gear['uuid'], application['domain_namespace'], gear['server_identity']) | |
| print "%s-%s\tCNAME\t%s" % (application['name'], application['domain_namespace'], application['gears'][0]['server_identity']) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment