forked from 3wordchant/capsul-flask
implement deleting capsuls
This commit is contained in:
@ -27,7 +27,7 @@ def double_check_capsul_address(id, ipv4):
|
||||
result = current_app.config["VIRTUALIZATION_MODEL"].get(id)
|
||||
if result.ipv4 != ipv4:
|
||||
ipv4 = result.ipv4
|
||||
get_model().updateVm(email=session["account"], id=id, ipv4=result.ipv4)
|
||||
get_model().update_vm_ip(email=session["account"], id=id, ipv4=result.ipv4)
|
||||
except:
|
||||
print(f"""
|
||||
the virtualization model threw an error in double_check_capsul_address of {id}:
|
||||
@ -55,12 +55,12 @@ def index():
|
||||
os=x['os'],
|
||||
created=x['created'].strftime("%b %d %Y")
|
||||
),
|
||||
vms
|
||||
list(filter(lambda x: not x['deleted'], vms))
|
||||
))
|
||||
|
||||
return render_template("capsuls.html", vms=vms, has_vms=len(vms) > 0)
|
||||
|
||||
@bp.route("/<string:id>")
|
||||
@bp.route("/<string:id>", methods=("GET", "POST"))
|
||||
@account_required
|
||||
def detail(id):
|
||||
|
||||
@ -73,16 +73,31 @@ def detail(id):
|
||||
if vm is None:
|
||||
return abort(404, f"{id} doesn't exist.")
|
||||
|
||||
vm["ipv4"] = double_check_capsul_address(vm["id"], vm["ipv4"])
|
||||
vm["created"] = vm['created'].strftime("%b %d %Y %H:%M")
|
||||
vm["ssh_public_keys"] = ", ".join(vm["ssh_public_keys"]) if len(vm["ssh_public_keys"]) > 0 else "<missing>"
|
||||
if vm['deleted']:
|
||||
return render_template("capsul-detail.html", vm=vm, delete=True, are_you_sure=True)
|
||||
|
||||
return render_template(
|
||||
"capsul-detail.html",
|
||||
vm=vm,
|
||||
durations=list(map(lambda x: x.strip("_"), metric_durations.keys())),
|
||||
duration=duration
|
||||
)
|
||||
if request.method == "POST":
|
||||
if 'are_you_sure' not in request.form or not request.form['are_you_sure']:
|
||||
|
||||
return render_template("capsul-detail.html", vm=vm, delete=True, are_you_sure=False)
|
||||
else:
|
||||
print(f"deleting {vm['id']} per user request ({session['account']})")
|
||||
current_app.config["VIRTUALIZATION_MODEL"].destroy(email=session['account'], id=id)
|
||||
get_model().delete_vm(email=session['account'], id=id)
|
||||
|
||||
return render_template("capsul-detail.html", vm=vm, delete=True, are_you_sure=True)
|
||||
|
||||
else:
|
||||
vm["ipv4"] = double_check_capsul_address(vm["id"], vm["ipv4"])
|
||||
vm["created"] = vm['created'].strftime("%b %d %Y %H:%M")
|
||||
vm["ssh_public_keys"] = ", ".join(vm["ssh_public_keys"]) if len(vm["ssh_public_keys"]) > 0 else "<missing>"
|
||||
|
||||
return render_template(
|
||||
"capsul-detail.html",
|
||||
vm=vm, delete=False,
|
||||
durations=list(map(lambda x: x.strip("_"), metric_durations.keys())),
|
||||
duration=duration
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/create", methods=("GET", "POST"))
|
||||
|
Reference in New Issue
Block a user