Exemple #1
0
def destroy_database(self, database, task_history=None, user=None):
    # register History
    AuditRequest.new_request("destroy_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.add_detail('Quarantine:')
        task_history.add_detail(
            'Since: {}'.format(database.quarantine_dt), level=2
        )
        task_history.add_detail(
            'Requested by: {}'.format(database.quarantine_user), level=2
        )
        task_history.add_detail('')
        task_history.add_detail('Loading Process...')

        databaseinfra = database.databaseinfra

        destroy_infra(databaseinfra=databaseinfra, task=task_history)

        task_history.update_status_for(
            TaskHistory.STATUS_SUCCESS, details='Database destroyed successfully')
        return
    finally:
        AuditRequest.cleanup_request()
def destroy_database(self, database, task_history=None, user=None):
    # register History
    AuditRequest.new_request("destroy_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...")

        databaseinfra = database.databaseinfra

        destroy_infra(databaseinfra=databaseinfra, task=task_history)

        task_history.update_status_for(
            TaskHistory.STATUS_SUCCESS,
            details='Database destroyed successfully')
        return
    finally:
        AuditRequest.cleanup_request()
Exemple #3
0
def purge_quarantine(self,):
    user = AccountUser.objects.get(username='******')
    AuditRequest.new_request("purge_quarantine", user, "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)))
        quarantine_time = Configuration.get_by_name_as_int('quarantine_retention_days')
        quarantine_time_dt = date.today() - timedelta(days=quarantine_time)

        databases = Database.objects.filter(is_in_quarantine=True,
                                            quarantine_dt__lte=quarantine_time_dt)

        for database in databases:
            if database.plan.provider == database.plan.CLOUDSTACK:
                databaseinfra = database.databaseinfra

                destroy_infra(databaseinfra=databaseinfra, task=task_history)
            else:
                database.delete()

            LOG.info("The database %s was deleted, because it was set to quarentine %d days ago" % (
                database.name, quarantine_time))

        task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details='Databases destroyed successfully')
        return

    except Exception:
        task_history.update_status_for(TaskHistory.STATUS_ERROR, details="Error")
        return
    finally:
        AuditRequest.cleanup_request()
Exemple #4
0
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 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 destroy_database(self, database, user=None):
	# register History
	AuditRequest.new_request("destroy_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...")

		databaseinfra = database.databaseinfra
		database.delete()

		destroy_infra(databaseinfra=databaseinfra, task=task_history)

		task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details='Database destroyed successfully')
		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
					
	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
def purge_quarantine(self,):
    user = AccountUser.objects.get(username='******')
    AuditRequest.new_request("purge_quarantine", user, "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)))
        quarantine_time = Configuration.get_by_name_as_int(
            'quarantine_retention_days')
        quarantine_time_dt = date.today() - timedelta(days=quarantine_time)

        databases = Database.objects.filter(is_in_quarantine=True,
                                            quarantine_dt__lte=quarantine_time_dt)

        for database in databases:
            if database.plan.provider == database.plan.CLOUDSTACK:
                databaseinfra = database.databaseinfra

                destroy_infra(databaseinfra=databaseinfra, task=task_history)
            else:
                database.delete()

            LOG.info("The database %s was deleted, because it was set to quarentine %d days ago" % (
                database.name, quarantine_time))

        task_history.update_status_for(
            TaskHistory.STATUS_SUCCESS, details='Databases destroyed successfully')
        return

    except Exception:
        task_history.update_status_for(
            TaskHistory.STATUS_ERROR, details="Error")
        return
    finally:
        AuditRequest.cleanup_request()
Exemple #9
0
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,
                             contacts=origin_database.contacts,
                             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()