diff --git a/app.py b/app.py index 2162180..369da55 100644 --- a/app.py +++ b/app.py @@ -75,7 +75,8 @@ def vm_details(vmid): vm['expire'] = get_vm_expire(vmid, app.config['VM_EXPIRE_MONTHS']).strftime('%m/%d/%Y') usage = get_user_usage(proxmox, 'proxstar') limits = get_user_usage_limits(user) - return render_template('vm_details.html', username='com6056', vm=vm, usage=usage, limits=limits) + usage_check = check_user_usage(proxmox, user, vm['config']['cores'], vm['config']['memory'], 0) + return render_template('vm_details.html', username='com6056', vm=vm, usage=usage, limits=limits, usage_check=usage_check) else: return '', 403 @@ -86,6 +87,11 @@ def vm_power(vmid, action): app.config['PROXMOX_USER'], app.config['PROXMOX_PASS']) if int(vmid) in get_user_allowed_vms(proxmox, user): + if action == 'start': + config = get_vm_config(proxmox, vmid) + usage_check = check_user_usage(proxmox, user, config['cores'], config['memory'], 0) + if usage_check: + return usage_check change_vm_power(proxmox, vmid, action) return '', 200 else: diff --git a/templates/vm_details.html b/templates/vm_details.html index 928c310..fca9d3a 100644 --- a/templates/vm_details.html +++ b/templates/vm_details.html @@ -10,8 +10,11 @@
{% if vm['qmpstatus'] == 'stopped' %} + {% if not usage_check %} - + {% else %} + Insufficient resources to start VM. + {% endif %} {% endif %} {% if vm['qmpstatus'] == 'paused' %} @@ -24,6 +27,11 @@ {% endif %} + {% if vm['qmpstatus'] == 'stopped' %} + + {% else %} + To delete VM, power it off. + {% endif %}
@@ -76,31 +84,27 @@
Cores
{{ vm['config']['cores'] * vm['config'].get('sockets', 1) }} - {% if limits['cpu'] - usage['cpu'] > 0 %} - {% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %} - - {% else %} - - {% endif %} + {% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %} + + {% else %} + {% endif %}
Memory
{{ vm['config']['memory'] // 1024 }}GB - {% if limits['mem'] - usage['mem'] > 0 %} - {% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %} - - {% else %} - - {% endif %} + {% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %} + + {% else %} + {% endif %}
Expiration