예제 #1
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('postgraas_instance_name',
                         required=True,
                         type=str,
                         help='name of the postgraas instance')
     parser.add_argument('db_name',
                         required=True,
                         type=str,
                         help='name of the db')
     parser.add_argument('db_username',
                         required=True,
                         type=str,
                         help='username of the db')
     parser.add_argument('db_pwd',
                         required=True,
                         type=str,
                         help='pass of the db user')
     args = parser.parse_args()
     db_credentials = {
         "db_name": args['db_name'],
         "db_username": args['db_username'],
         "db_pwd": args['db_pwd'],
         "host": pg.get_hostname(),
         "port": pg.get_open_port()
     }
     if DBInstance.query.filter_by(
             postgraas_instance_name=args['postgraas_instance_name']).first(
             ):
         return {
             'msg':
             "postgraas_instance_name already exists {}".format(
                 args['postgraas_instance_name'])
         }
     try:
         db_credentials['container_id'] = pg.create_postgres_instance(
             args['postgraas_instance_name'], db_credentials)
     except APIError as e:
         return {'msg': str(e)}
     db_entry = DBInstance(
         postgraas_instance_name=args['postgraas_instance_name'],
         db_name=args['db_name'],
         username=args['db_username'],
         password="",
         hostname=db_credentials['host'],
         port=db_credentials['port'],
         container_id=db_credentials['container_id'])
     db.session.add(db_entry)
     db.session.commit()
     db_credentials["postgraas_instance_id"] = db_entry.id
     return db_credentials
예제 #2
0
def create_db_container():
    config = get_config()
    db_credentials = {
            "db_name": config.get('metadb', 'db_name'),
            "db_username": config.get('metadb', 'db_username'),
            "db_pwd": config.get('metadb', 'db_pwd'),
            "host": config.get('metadb', 'host'),
            "port": config.get('metadb', 'port')
        }
    try:
        db_credentials['container_id'] = pg.create_postgres_instance('postgraas_master_db', db_credentials)
    except ValueError as e:
        print "warning container already exists"
        postrgaas_db = pg.get_container_by_name('postgraas_master_db')
        db_credentials['container_id'] = postrgaas_db['Id']
    return db_credentials