def create_database(self, name, plan, environment, team, project, description, user=None): # register History task_history = TaskHistory.register(request=self.request, user=user) 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.update_details(persist=True, details="Loading Process...") result = make_infra(plan=plan, environment=environment, name=name, task=task_history) if result['created']==False: if 'exceptions' in result: error = "\n\n".join(": ".join(err) for err in result['exceptions']['error_codes']) traceback = "\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 database = Database.provision(name, result['databaseinfra']) database.team = team database.project = project database.description = description database.save() task_history.update_dbid(db=database) task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details='Database created successfully') return
def create_database(self, name, plan, environment, team, project, description, task_history=None, user=None): AuditRequest.new_request("create_database", user, "localhost") try: worker_name = get_worker_name() task_history = TaskHistory.register(request=self.request, task_history=task_history, user=user, worker_name=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.update_details(persist=True, details="Loading Process...") result = make_infra(plan=plan, environment=environment, name=name, team=team, project=project, description=description, task=task_history, ) if result['created'] == False: if 'exceptions' in result: error = "\n".join(": ".join(err) for err in result['exceptions']['error_codes']) traceback = "\nException Traceback\n".join( result['exceptions']['traceback']) error = "{}\n{}\n{}".format(error, traceback, error) 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='Database created successfully') 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()
def clone_database(self, origin_database, clone_name, user=None): # register History AuditRequest.new_request("clone_database", self.request.kwargs["user"], "localhost") try: task_history = TaskHistory.register(request=self.request, user=user) LOG.info("origin_database: %s" % origin_database) dest_database = Database.objects.get(pk=origin_database.pk) dest_database.name = clone_name dest_database.pk = None task_history.update_details(persist=True, details="Loading Process...") result = make_infra(plan=origin_database.plan, environment=origin_database.environment, name=clone_name, task=task_history) 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 finally: AuditRequest.cleanup_request() dest_database.databaseinfra = result['databaseinfra'] dest_database.save() LOG.info("dest_database: %s" % dest_database) LOG.info("id: %s | task: %s | kwargs: %s | args: %s" % ( self.request.id, self.request.task, self.request.kwargs, str(self.request.args))) try: args = get_clone_args(origin_database, dest_database) script_name = factory_for(origin_database.databaseinfra).clone() return_code, output = call_script(script_name, working_dir=settings.SCRIPTS_PATH, args=args, split_lines=False) LOG.info("%s - return code: %s" % (self.request.id, return_code)) if return_code != 0: task_history.update_status_for(TaskHistory.STATUS_ERROR, details=output + "\nTransaction rollback") LOG.error("task id %s - error occurred. Transaction rollback" % self.request.id) rollback_database(dest_database) else: task_history.update_dbid(db=dest_database) task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details=output) except SoftTimeLimitExceeded: LOG.error("task id %s - timeout exceeded" % self.request.id) task_history.update_status_for(TaskHistory.STATUS_ERROR, details="timeout exceeded") rollback_database(dest_database) except Exception, e: LOG.error("task id %s error: %s" % (self.request.id, e)) task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e) rollback_database(dest_database)
def create_database(self, name, plan, environment, team, project, description, user=None): # register History AuditRequest.new_request("create_database", self.request.args[-1], "localhost") try: task_history = TaskHistory.register(request=self.request, user=user) 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.update_details(persist=True, details="Loading Process...") result = make_infra(plan=plan, environment=environment, name=name, task=task_history) if result['created']==False: if 'exceptions' in result: error = "\n".join(": ".join(err) for err in result['exceptions']['error_codes']) traceback = "\nException Traceback\n".join(result['exceptions']['traceback']) error = "{}\n{}\n{}".format(error, traceback, error) else: error = "There is not any infra-structure to allocate this database." task_history.update_status_for(TaskHistory.STATUS_ERROR, details=error) return database = Database.provision(name, result['databaseinfra']) database.team = team database.project = project database.description = description database.save() task_history.update_dbid(db=database) from util import laas #laas.register_database_laas(database) task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details='Database created successfully') return except Exception, e: traceback = full_stack() LOG.error("Ops... something went wrong: %s" % e) LOG.error(traceback) if 'database' in locals() and database.id: task_history.update_status_for(TaskHistory.STATUS_WARNING, details=traceback) else: if 'result' in locals() and result['created']: destroy_infra(databaseinfra = result['databaseinfra']) task_history.update_status_for(TaskHistory.STATUS_ERROR, details=traceback) return
def clone_database(self, origin_database, clone_name, user=None): # register History AuditRequest.new_request("clone_database", self.request.kwargs["user"], "localhost") try: task_history = TaskHistory.register(request=self.request, user=user) LOG.info("origin_database: %s" % origin_database) dest_database = Database.objects.get(pk=origin_database.pk) dest_database.name = clone_name dest_database.pk = None task_history.update_details(persist=True, details="Loading Process...") result = make_infra(plan=origin_database.plan, environment=origin_database.environment, name=clone_name, task=task_history) 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 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_history.update_status_for(TaskHistory.STATUS_ERROR, details=traceback) return