def clone_database(self, origin_database, clone_name, plan, environment, task_history=None,user=None): AuditRequest.new_request("clone_database", user, "localhost") try: worker_name = get_worker_name() LOG.info("id: %s | task: %s | kwargs: %s | args: %s" % ( self.request.id, self.request.task, self.request.kwargs, str(self.request.args))) task_history = TaskHistory.register(request=self.request, task_history=task_history, user=user, worker_name=worker_name) LOG.info("origin_database: %s" % origin_database) task_history.update_details(persist=True, details="Loading Process...") result = clone_infra(plan=plan, environment=environment, name=clone_name, team= origin_database.team, project= origin_database.project, description= origin_database.description, task=task_history, clone= origin_database, ) if result['created']==False: if 'exceptions' in result: error = "\n\n".join(": ".join(err) for err in result['exceptions']['error_codes']) traceback = "\n\nException Traceback\n".join(result['exceptions']['traceback']) error = "{}\n{}".format(error, traceback) else: error = "There is not any infra-structure to allocate this database." task_history.update_status_for(TaskHistory.STATUS_ERROR, details=error) return task_history.update_dbid(db=result['database']) task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details='\nDatabase cloned successfully') except SoftTimeLimitExceeded: LOG.error("task id %s - timeout exceeded" % self.request.id) task_history.update_status_for(TaskHistory.STATUS_ERROR, details="timeout exceeded") if 'result' in locals() and result['created']: destroy_infra(databaseinfra = result['databaseinfra'], task=task_history) return except Exception, e: traceback = full_stack() LOG.error("Ops... something went wrong: %s" % e) LOG.error(traceback) if 'result' in locals() and result['created']: destroy_infra(databaseinfra = result['databaseinfra'], task=task_history) task_history.update_status_for(TaskHistory.STATUS_ERROR, details=traceback) return
def clone_database(self, origin_database, clone_name, plan, environment, task_history=None, user=None): AuditRequest.new_request("clone_database", user, "localhost") try: worker_name = get_worker_name() LOG.info("id: %s | task: %s | kwargs: %s | args: %s" % (self.request.id, self.request.task, self.request.kwargs, str(self.request.args))) task_history = TaskHistory.register(request=self.request, task_history=task_history, user=user, worker_name=worker_name) LOG.info("origin_database: %s" % origin_database) task_history.update_details(persist=True, details="Loading Process...") result = clone_infra(plan=plan, environment=environment, name=clone_name, team=origin_database.team, project=origin_database.project, description=origin_database.description, task=task_history, clone=origin_database, subscribe_to_email_events=origin_database. subscribe_to_email_events) if result['created'] is False: if 'exceptions' in result: error = "\n\n".join( ": ".join(err) for err in result['exceptions']['error_codes']) traceback = "\n\nException Traceback\n".join( result['exceptions']['traceback']) error = "{}\n{}".format(error, traceback) else: error = "There is not any infra-structure to allocate this database." task_history.update_status_for(TaskHistory.STATUS_ERROR, details=error) return task_history.update_dbid(db=result['database']) task_history.update_status_for( TaskHistory.STATUS_SUCCESS, details='\nDatabase cloned successfully') except SoftTimeLimitExceeded: LOG.error("task id %s - timeout exceeded" % self.request.id) task_history.update_status_for(TaskHistory.STATUS_ERROR, details="timeout exceeded") if 'result' in locals() and result['created']: destroy_infra(databaseinfra=result['databaseinfra'], task=task_history) return except Exception as e: traceback = full_stack() LOG.error("Ops... something went wrong: %s" % e) LOG.error(traceback) if 'result' in locals() and result['created']: destroy_infra(databaseinfra=result['databaseinfra'], task=task_history) task_history.update_status_for(TaskHistory.STATUS_ERROR, details=traceback) return finally: AuditRequest.cleanup_request()