def create_db(self, db_srv_host, db_srv_port, db_serv_name,\ db_end_point, db_dbName, db_user_name, db_password,\ db_conn_protocol): host_connection = db_conn_protocol + "://" + db_srv_host + ":" + str( db_srv_port) client = ArangoClient(hosts=host_connection) logger.debug("Connection reuse: " + str(self.reuse_connection)) if not self.reuse_connection: API_ENDPOINT = host_connection + "/_db/_system/" + db_end_point + \ "/" + db_serv_name print("API endpoint: " + API_ENDPOINT) if db_dbName: logger.info("DB name preferrence: " + str(db_dbName)) if db_user_name: logger.info("DB user name preferrence: " + str(db_user_name)) if db_password: logger.info( "Password preference for managed connection was indicated !" ) api_data = {self.mscp.DB_NAME : db_dbName,\ self.mscp.DB_USER_NAME: db_user_name,\ self.mscp.DB_PASSWORD: db_password } logger.info("Requesting a managed service database...") r = requests.post(url=API_ENDPOINT, json=api_data, verify=False) if r.status_code == 409 or r.status_code == 400: logger.error( "It appears that you are attempting to connecting using \ existing connection information. So either set reconnect = True when you create ArangoPipeAdmin or recreate a connection config and try again!" ) return assert r.status_code == 200, \ "Managed DB endpoint is unavailable !, reason: " + r.reason + " err code: " +\ str(r.status_code) result = json.loads(r.text) logger.info("Managed service database was created !") ms_dbName = result['dbName'] ms_user_name = result['username'] ms_password = result['password'] self.cfg['arangodb'][self.mscp.DB_NAME] = ms_dbName self.cfg['arangodb'][self.mscp.DB_USER_NAME] = ms_user_name self.cfg['arangodb'][self.mscp.DB_PASSWORD] = ms_password self.cfg['arangodb'][self.mscp.DB_SERVICE_HOST] = db_srv_host self.cfg['arangodb'][self.mscp.DB_SERVICE_NAME] = db_serv_name self.cfg['arangodb'][self.mscp.DB_SERVICE_END_POINT] = db_end_point self.cfg['arangodb'][self.mscp.DB_SERVICE_PORT] = db_srv_port self.cfg['arangodb'][self.mscp.DB_CONN_PROTOCOL] = db_conn_protocol else: if self.use_supp_config_to_reconnect: ms_dbName = self.cfg['arangodb'][self.mscp.DB_NAME] ms_user_name = self.cfg['arangodb'][self.mscp.DB_USER_NAME] ms_password = self.cfg['arangodb'][self.mscp.DB_PASSWORD] else: disk_cfg = ArangoPipeConfig() pcfg = disk_cfg.get_cfg() # persisted config values ms_dbName = pcfg['arangodb'][self.mscp.DB_NAME] ms_user_name = pcfg['arangodb'][self.mscp.DB_USER_NAME] ms_password = pcfg['arangodb'][self.mscp.DB_PASSWORD] self.config = disk_cfg self.cfg = disk_cfg.cfg # Connect to arangopipe database as administrative user. #This returns an API wrapper for "test" database. print("Host Connection: " + str(host_connection)) client = ArangoClient(hosts= host_connection,\ http_client=CustomHTTPClient(username = ms_user_name,\ password = ms_password)) db = client.db(ms_dbName, ms_user_name, ms_password) self.db = db return
def get_config(self): apc = ArangoPipeConfig() return apc.get_cfg()