def delete_job(request, project_name): user = request.user project = Project.objects.get(name=project_name) if user.has_perm("execute_proj", project) == False: raise PopupException("Sorry, you have not right to manage the project!") data = False try: job_pk = request.GET.get("job_pk") Job.objects.get(pk=job_pk).delete() data = True except Exception: data = False return render_json(data)
def delete_job(request, project_name): user = request.user project = Project.objects.get(name=project_name) if (user.has_perm('execute_proj', project) == False): raise PopupException( 'Sorry, you have not right to manage the project!') data = False try: job_pk = request.GET.get('job_pk') Job.objects.get(pk=job_pk).delete() data = True except Exception: data = False return render_json(data)
def result_json(request, project_name, job_pk): job = Job.objects.get(pk=job_pk) color = re.compile('(.\[0\;\d+m)?(.*?)(.\[\dm)?') job.result_stdout = color.sub(r'\2', job.result_stdout) job.result_stderr = color.sub(r'\2', job.result_stderr) job.result_traceback = color.sub(r'\2', job.result_traceback) data = { 'status': job.status, 'result_stdout': job.result_stdout, 'result_stderr': job.result_stderr, 'result_traceback': job.result_traceback } if job.status == "successful" or job.status == "failed": if job.email != '': sendmail(job.email, job.status, job_pk, project_name) return render_json(data)
def result_json(request, project_name, job_pk): job = Job.objects.get(pk=job_pk) color = re.compile("(.\[0\;\d+m)?(.*?)(.\[\dm)?") job.result_stdout = color.sub(r"\2", job.result_stdout) job.result_stderr = color.sub(r"\2", job.result_stderr) job.result_traceback = color.sub(r"\2", job.result_traceback) data = { "status": job.status, "result_stdout": job.result_stdout, "result_stderr": job.result_stderr, "result_traceback": job.result_traceback, } if job.status == "successful" or job.status == "failed": if job.email != "": sendmail(job.email, job.status, job_pk, project_name) return render_json(data)
def delete_template(request, project_name): user = request.user project = Project.objects.get(name=project_name) if user.has_perm("config_proj", project) == False: raise PopupException("Sorry, you have not right to config the project!") data = False try: template_pk = request.GET.get("template_pk") JobTemplate.objects.get(pk=template_pk).delete() data = True except Exception: data = False return render_json(data)
def delete_template(request, project_name): user = request.user project = Project.objects.get(name=project_name) if (user.has_perm('config_proj', project) == False): raise PopupException( 'Sorry, you have not right to config the project!') data = False try: template_pk = request.GET.get('template_pk') JobTemplate.objects.get(pk=template_pk).delete() data = True except Exception: data = False return render_json(data)
def deploykey(request, project_name): user = request.user project = Project.objects.get(name=project_name) if (user.has_perm('execute_proj', project) == False): raise PopupException( 'Sorry, you have not right to execute the project!') result = [] page_errors = None if request.method == 'POST': inventory = request.POST.get('inventory') hosts = request.POST.get('hosts') user = request.POST.get('user') password = request.POST.get('password') key = request.POST.get('sshkey') if inventory == '<--None-->': file_content = hosts if file_content.count(','): file_content = '\n'.join(file_content.split(',')) elif file_content.count(';'): file_content = '\n'.join(file_content.split(';')) else: file_content = '\n'.join(file_content.split(' ')) file_name = 'hosts' inventory = create_tmp_task_file(project_name, file_name, file_content) inventory = get_inventory_local_path(project_name, inventory) hostlist = get_hosts(inventory, hosts) result = get_sshkey_deploy(hostlist, user, password, key) results = {} for i in range(len(result)): results[i] = result[i] results = [results] return render_json(results) return render( "ansible/deploykey.html", request, { 'project': project, 'result': result, 'page_errors': page_errors, 'request': request, })
def delete_project(request, project_name): user = request.user project = Project.objects.get(name=project_name) if user.has_perm("manage_proj", project) == False: raise PopupException("Sorry, you have not right to manage the project!") data = False try: Job.objects.filter(project=project).delete() JobTemplate.objects.filter(project=project).delete() Package.objects.filter(project=project).delete() Project.objects.get(name=project_name).delete() delete_project_dir(project_name) data = True except Exception: data = False return render_json(data)
def delete_project(request, project_name): user = request.user project = Project.objects.get(name=project_name) if (user.has_perm('manage_proj', project) == False): raise PopupException( 'Sorry, you have not right to manage the project!') data = False try: Job.objects.filter(project=project).delete() JobTemplate.objects.filter(project=project).delete() Package.objects.filter(project=project).delete() Project.objects.get(name=project_name).delete() delete_project_dir(project_name) data = True except Exception: data = False return render_json(data)
def process_exception(self, request, exception): import traceback tb = traceback.format_exc() if isinstance(exception, PopupException): return exception.response(request) if isinstance(exception, StructuredException): if request.ajax: response = render_json(exception.response_data) response[MIDDLE_WARE_HEADER] = 'EXCEPTION' response.status_code = getattr(exception, 'error_code', 500) return response else: response = render("error.html", request,dict(error=exception.response_data.get("message"))) response.status_code = getattr(exception, 'error_code', 500) return response return None
def deploykey(request, project_name): user = request.user project = Project.objects.get(name=project_name) if user.has_perm("execute_proj", project) == False: raise PopupException("Sorry, you have not right to execute the project!") result = [] page_errors = None if request.method == "POST": inventory = request.POST.get("inventory") hosts = request.POST.get("hosts") user = request.POST.get("user") password = request.POST.get("password") key = request.POST.get("sshkey") if inventory == "<--None-->": file_content = hosts if file_content.count(","): file_content = "\n".join(file_content.split(",")) elif file_content.count(";"): file_content = "\n".join(file_content.split(";")) else: file_content = "\n".join(file_content.split(" ")) file_name = "hosts" inventory = create_tmp_task_file(project_name, file_name, file_content) inventory = get_inventory_local_path(project_name, inventory) hostlist = get_hosts(inventory, hosts) result = get_sshkey_deploy(hostlist, user, password, key) results = {} for i in range(len(result)): results[i] = result[i] results = [results] return render_json(results) return render( "ansible/deploykey.html", request, {"project": project, "result": result, "page_errors": page_errors, "request": request}, )
def process_exception(self, request, exception): import traceback tb = traceback.format_exc() if isinstance(exception, PopupException): return exception.response(request) if isinstance(exception, StructuredException): if request.ajax: response = render_json(exception.response_data) response[MIDDLE_WARE_HEADER] = 'EXCEPTION' response.status_code = getattr(exception, 'error_code', 500) return response else: response = render( "error.html", request, dict(error=exception.response_data.get("message"))) response.status_code = getattr(exception, 'error_code', 500) return response return None