コード例 #1
0
    def do(self, workflow_dict):
        try:

            if 'databaseinfra' not in workflow_dict \
                    or 'clone' not in workflow_dict:
                return False

            args = get_clone_args(
                workflow_dict['clone'], workflow_dict['database'])
            script_name = factory_for(
                workflow_dict['clone'].databaseinfra).clone()

            return_code, output = call_script(
                script_name, working_dir=settings.SCRIPTS_PATH, args=args, split_lines=False,)

            LOG.info("Script Output: {}".format(output))
            LOG.info("Return code: {}".format(return_code))

            if return_code != 0:
                workflow_dict['exceptions']['traceback'].append(output)
                return False

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0017)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #2
0
def clone_database(self, origin_database, dest_database, user=None):
    
    #register History
    task_history = TaskHistory.register(request=self.request, user=user)
    
    LOG.info("origin_database: %s" % origin_database)
    LOG.info("dest_database: %s" % dest_database)
    # task_state = self.AsyncResult(self.request.id).state)
    LOG.info("id: %s | task: %s | kwargs: %s | args: %s" % (self.request.id,
                                                            self.request.task,
                                                            self.request.kwargs,
                                                            str(self.request.args)))

    args = get_clone_args(origin_database, dest_database)

    try:
        script_name = factory_for(origin_database.databaseinfra).clone()
        #script_name = "dummy_clone.sh"
        return_code, output = call_script(script_name, working_dir=settings.SCRIPTS_PATH, args=args)
        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)
            LOG.error("task id %s - error occurred. Transaction rollback" % self.request.id)
            rollback(dest_database)
        else:
            task_history.update_status_for(TaskHistory.STATUS_SUCCESS)
    except SoftTimeLimitExceeded:
        LOG.error("task id %s - timeout exceeded" % self.request.id)
        task_history.update_status_for(TaskHistory.STATUS_ERROR, details="timeout exceeded")
    except Exception, e:
        LOG.error("task id %s error: %s" % (self.request.id, e))
        task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
コード例 #3
0
    def do(self, workflow_dict):
        try:

            if 'databaseinfra' not in workflow_dict \
                    or 'clone' not in workflow_dict:
                return False

            args = get_clone_args(workflow_dict['clone'],
                                  workflow_dict['database'])
            script_name = factory_for(
                workflow_dict['clone'].databaseinfra).clone()

            return_code, output = call_script(
                script_name,
                working_dir=settings.SCRIPTS_PATH,
                args=args,
                split_lines=False,
            )

            LOG.info("Script Output: {}".format(output))
            LOG.info("Return code: {}".format(return_code))

            if return_code != 0:
                workflow_dict['exceptions']['traceback'].append(output)
                return False

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0017)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #4
0
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)
コード例 #5
0
def auto_upgrade_app(appname, app_curr_ver):
    while True:
        print("checking available app versions on dockerhub")
        resp = get_docker_url(appname)
        #print("%s" % resp)
        for data in resp['results']:
            pattern = "^[.|0-9]+$"
            #print("dh version - %s" % data['name'])
            if re.match(pattern, data['name']):
                if data['name'] > app_curr_ver:
                    print("need to upgrade the app on dnac to latest version %s on dockerhub" % data['name'])
                    # call docker script to pull new version 
                    dir_path = os.path.dirname(os.path.realpath("docker_image_cmd.sh"))
                    call_script(os.path.join(dir_path, "docker_image_cmd.sh"), appname, data['name'])
                    # call dnac api to update and upgrade the app on all devices
                    new_docker_image_path = os.path.join(dir_path,appname+"_"+data['name']+".tar")
                    resp = update_app_version(appname, app_curr_ver, new_docker_image_path)
                    print("Successfully updated app %s on Cisco DNAC" % (appname))# resp["version"]))
                    break
            else:
                continue
        app_curr_ver = find_app_ver_on_dnac(appname)
        print("Current app version on DNAC - %s" % app_curr_ver)
        time.sleep(30)
コード例 #6
0
	    from util import laas
	    #laas.register_database_laas(dest_database)
	except Exception, e:
	    traceback = full_stack()
	    LOG.error("Ops... something went wrong: %s" % e)
	    LOG.error(traceback)
	    task_history.update_details(persist=True, details='\n' + traceback)


	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)