def get_constraint(request, name, stage): try: deploy_constraint = environ_hosts_helper.get_deploy_constraint(request, name, stage) return HttpResponse(json.dumps(deploy_constraint), status=200, content_type="application/json") except Exception as e: log.error("get constraint failed with {}", e) return HttpResponse(json.dumps({'html': 'Failed to get deploy constraint.'}), status=500, content_type="application/json")
def remove_constraint(request, name, stage): try: deploy_constraint = environ_hosts_helper.get_deploy_constraint(request, name, stage) tag_name = deploy_constraint.get('constraintKey') environ_hosts_helper.remove_deploy_constraint(request, name, stage) environ_hosts_helper.remove_host_tags(request, name, stage, tag_name) return redirect('/env/{}/{}/constraint'.format(name, stage)) except Exception as e: log.error("remove constraint failed with {}", e) return redirect('/env/{}/{}/constraint'.format(name, stage))
def edit_constraint(request, name, stage): try: deploy_constraint = environ_hosts_helper.get_deploy_constraint(request, name, stage) if not deploy_constraint: return HttpResponse(json.dumps({'html': 'Failed to find deploy constraint.'}), status=404, content_type="application/json") max_parallel = request.POST.get("max_parallel") constraint_type = request.POST.get('constraint_type', environs_helper.DEPLOY_CONSTRAINT_TYPES[0]) environ_hosts_helper.update_deploy_constraint(request, name, stage, { 'maxParallel': max_parallel, 'constraintType': constraint_type }) return redirect('/env/{}/{}/constraint'.format(name, stage)) except Exception as e: log.error("get constraint failed with {}", e) return HttpResponse(json.dumps({'html': 'Failed to get deploy constraint.'}), status=500, content_type="application/json")
def get(self, request, name, stage): envs = environs_helper.get_all_env_stages(request, name) stages, env = common.get_all_stages(envs, stage) context = {"envs": envs, "env": env, "stages": stages} deploy_constraint = environ_hosts_helper.get_deploy_constraint( request, name, stage) if deploy_constraint: max_parallel = deploy_constraint.get("maxParallel", None) tag_name = deploy_constraint.get("constraintKey", None) context["tag_name"] = tag_name context["max_parallel"] = max_parallel context["state"] = deploy_constraint.get("state", "UNKNOWN") context["show_remove_btn"] = True else: context["show_remove_btn"] = False return render(request, 'environs/env_host_tags.html', context)
def get(self, request, name, stage): envs = environs_helper.get_all_env_stages(request, name) stages, env = common.get_all_stages(envs, stage) context = { "envs": envs, "env": env, "stages": stages } deploy_constraint = environ_hosts_helper.get_deploy_constraint(request, name, stage) if deploy_constraint: max_parallel = deploy_constraint.get("maxParallel", None) tag_name = deploy_constraint.get("constraintKey", None) context["tag_name"] = tag_name context["max_parallel"] = max_parallel context["state"] = deploy_constraint.get("state", "UNKNOWN") context["constraint_type"] = deploy_constraint.get("constraintType", environs_helper.DEPLOY_CONSTRAINT_TYPES[0]) context["show_remove_btn"] = True else: context["show_remove_btn"] = False context["constraintTypes"] = environs_helper.DEPLOY_CONSTRAINT_TYPES return render(request, 'environs/env_host_tags.html', context)