From 8d95c373b54c9f83057f7b836fa469fa21f42455 Mon Sep 17 00:00:00 2001 From: Will Nilges Date: Fri, 9 Sep 2022 13:42:47 -0400 Subject: [PATCH] Impose limits on all VM creation This prevents people from trying to allocate more resources than they have available in total. This isn't the best solution, since it may prevent people from having many VMs with only a few started up, but that's a problem for when users start complaining. --- proxstar/__init__.py | 7 ++----- proxstar/static/js/script.js | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/proxstar/__init__.py b/proxstar/__init__.py index 5d5e1a6..43b1803 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -485,16 +485,13 @@ def create(): if iso != 'none': iso = '{}:iso/{}'.format(app.config['PROXMOX_ISO_STORAGE'], iso) if not user.rtp: - if template == 'none': - usage_check = user.check_usage(0, 0, disk) - else: - usage_check = user.check_usage(cores, memory, disk) + usage_check = user.check_usage(cores, memory, disk) username = user.name else: usage_check = None username = request.form['user'] if usage_check: - return usage_check + return usage_check, 403 else: valid, available = ( check_hostname(starrs, name) if app.config['USE_STARRS'] else (True, True) diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index 53bd1cd..adb8392 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -284,9 +284,9 @@ $("#create-vm").click(function(){ swal("Uh oh...", "Invalid SSH key!", "error"); } else if (disk > max_disk) { swal("Uh oh...", `You do not have enough disk resources available! Please lower the VM disk size to ${max_disk}GB or lower.`, "error"); - } else if (template != 'none' && cores > max_cpu) { + } else if (cores > max_cpu) { swal("Uh oh...", `You do not have enough CPU resources available! Please lower the VM cores to ${max_cpu} or lower.`, "error"); - } else if (template != 'none' && mem/1024 > max_mem) { + } else if (mem/1024 > max_mem) { swal("Uh oh...", `You do not have enough memory resources available! Please lower the VM memory to ${max_mem}GB or lower.`, "error"); } else { fetch(`/hostname/${name}`, {