capacity limiter and general cleanup

This commit is contained in:
2020-05-13 13:56:43 -05:00
parent a43b3b4e1e
commit 403506a0b0
10 changed files with 121 additions and 50 deletions

View File

@ -75,7 +75,7 @@ def detail(id):
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 "<deleted>"
vm["ssh_public_keys"] = ", ".join(vm["ssh_public_keys"]) if len(vm["ssh_public_keys"]) > 0 else "<missing>"
return render_template(
"capsul-detail.html",
@ -92,6 +92,7 @@ def create():
operating_systems = get_model().operating_systems_dict()
ssh_public_keys = get_model().list_ssh_public_keys_for_account(session["account"])
account_balance = get_account_balance()
capacity_avaliable = current_app.config["VIRTUALIZATION_MODEL"].capacity_avaliable(512*1024*1024)
errors = list()
created_os = None
@ -130,6 +131,13 @@ def create():
if len(posted_keys) == 0:
errors.append("At least one SSH Public Key is required")
capacity_avaliable = current_app.config["VIRTUALIZATION_MODEL"].capacity_avaliable(vm_sizes[size]['memory_mb']*1024*1024)
if not capacity_avaliable:
errors.append("""
host(s) at capacity. no capsuls can be created at this time. sorry.
""")
if len(errors) == 0:
id = makeCapsulId()
get_model().create_vm(
@ -157,9 +165,13 @@ def create():
for error in errors:
flash(error)
if not capacity_avaliable:
print(f"when capsul capacity is restored, send an email to {session['account']}")
return render_template(
"create-capsul.html",
created_os=created_os,
capacity_avaliable=capacity_avaliable,
account_balance=format(account_balance, '.2f'),
ssh_public_keys=ssh_public_keys,
ssh_public_key_count=len(ssh_public_keys),