diff --git a/sld-dashboard/app/home/routes.py b/sld-dashboard/app/home/routes.py index 37653ad8..289f192d 100644 --- a/sld-dashboard/app/home/routes.py +++ b/sld-dashboard/app/home/routes.py @@ -435,6 +435,48 @@ def get_plan(deploy_id): except ValueError: return redirect(url_for("base_blueprint.logout")) +@blueprint.route("/plan/redeploy/") +@login_required +def relaunch_plan(deploy_id): + try: + token = decrypt(r.get(current_user.id)) + # Check if token no expired + check_unauthorized_token(token) + endpoint = f"deploy/{deploy_id}" + + response = request_url( + verb="GET", uri=f"{endpoint}", headers={"Authorization": f"Bearer {token}"} + ) + content = response.get("json") + data = { + "start_time": content["start_time"], + "destroy_time": content["destroy_time"], + "stack_branch": content["stack_branch"], + "tfvar_file": content["tfvar_file"], + "project_path": content["project_path"], + "variables": content["variables"], + } + endpoint = f"plan/{deploy_id}" + response = request_url( + verb="PATCH", + uri=f"{endpoint}", + headers={"Authorization": f"Bearer {token}"}, + json=data, + ) + + if response.get("status_code") == 202: + flash(f"planning deploy") + else: + flash(response["json"]["detail"], "error") + return redirect( + url_for("home_blueprint.route_template", template="deploys-list") + ) + except TemplateNotFound: + return render_template("page-404.html"), 404 + except TypeError: + return redirect(url_for("base_blueprint.logout")) + except Exception: + return render_template("page-500.html"), 500 @blueprint.route( "/edit-schedule", methods=["GET", "POST"], defaults={"deploy_id": None} diff --git a/sld-dashboard/app/home/templates/deploys-list.html b/sld-dashboard/app/home/templates/deploys-list.html index a621f5d0..8fecd188 100644 --- a/sld-dashboard/app/home/templates/deploys-list.html +++ b/sld-dashboard/app/home/templates/deploys-list.html @@ -173,10 +173,12 @@

All Deploys

{% else %} - - + +