diff --git a/agent.py b/agent.py new file mode 100644 index 0000000..181d3df --- /dev/null +++ b/agent.py @@ -0,0 +1,5 @@ +from websockify.websocket import * +from websockify.websocketproxy import * + +server = WebSocketProxy(listen_port='10000', target_port='6000') +server.start_server() diff --git a/app.py b/app.py index 5f0dfd2..a47c3aa 100644 --- a/app.py +++ b/app.py @@ -27,6 +27,7 @@ cache = SimpleCache() def list_vms(user=None): rtp_view = False rtp = 'rtp' in session['userinfo']['groups'] + active = 'active' in session['userinfo']['groups'] proxmox = connect_proxmox() if user and not rtp: return '', 403 @@ -45,7 +46,12 @@ def list_vms(user=None): user = session['userinfo']['preferred_username'] vms = get_vms_for_user(proxmox, user) return render_template( - 'list_vms.html', username=user, rtp=rtp, rtp_view=rtp_view, vms=vms) + 'list_vms.html', + username=user, + rtp=rtp, + active=active, + rtp_view=rtp_view, + vms=vms) @app.route("/isos") @@ -304,6 +310,18 @@ def reset_limits(user): return '', 403 +@app.route('/user//delete', methods=['POST']) +@auth.oidc_auth +def delete_user(user): + if 'rtp' in session['userinfo']['groups']: + proxmox = connect_proxmox() + delete_user_pool(proxmox, user) + cache.delete('vms') + return '', 200 + else: + return '', 403 + + @app.route('/vm//rrd/') @auth.oidc_auth def send_rrd(vmid, path): diff --git a/proxmox.py b/proxmox.py index 863ea02..3484cb8 100644 --- a/proxmox.py +++ b/proxmox.py @@ -36,6 +36,8 @@ def get_vms_for_rtp(proxmox): for pool in pools: pool_dict = dict() pool_dict['user'] = pool + pool_dict['vms'] = get_vms_for_user(proxmox, pool) + pool_dict['num_vms'] = len(pool_dict['vms']) pool_dict['usage'] = get_user_usage(proxmox, pool) pool_dict['limits'] = get_user_usage_limits(pool) pool_dict['percents'] = get_user_usage_percent( @@ -269,3 +271,12 @@ def get_rrd_for_vm(proxmox, vmid, source, time): node = proxmox.nodes(get_vm_node(proxmox, vmid)) image = node.qemu(vmid).rrd.get(ds=source, timeframe=time)['image'] return image + + +def delete_user_pool(proxmox, pool): + proxmox.pools(pool).delete() + users = proxmox.access.users.get() + if any(user['userid'] == "{}@csh.rit.edu".format(pool) for user in users): + if 'rtp' not in proxmox.access.users( + "{}@csh.rit.edu".format(pool)).get()['groups']: + proxmox.access.users("{}@csh.rit.edu".format(pool)).delete() diff --git a/static/css/styles.css b/static/css/styles.css index bc09c82..d19bd2e 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -90,10 +90,9 @@ table, th, td { line-height: 1; } -.proxstar-limitbtn { - padding-top: 0px; - padding-bottom: 0px; - width: 70px; +.proxstar-poolbtn { + padding: 0; + width: 55px; height: 25px; margin-top: 10px; } diff --git a/static/js/script.js b/static/js/script.js index b835b37..d4c8bf0 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -654,7 +654,7 @@ $(".edit-limit").click(function(){ } }); }).then(() => { - window.location = `/limits`; + window.location = "/"; }); } }).catch(err => { @@ -692,7 +692,7 @@ $(".reset-limit").click(function(){ icon: "success", }); }).then(() => { - window.location = `/limits`; + window.location = "/"; }).catch(err => { if (err) { swal("Uh oh...", `Unable to reset the usage limits for ${user}. Please try again later.`, "error"); @@ -704,3 +704,41 @@ $(".reset-limit").click(function(){ } }); }); + +$(".delete-user").click(function(){ + const user = $(this).data('user') + swal({ + title: `Are you sure you want to delete the pool for ${user}?`, + icon: "warning", + buttons: { + cancel: true, + delete: { + text: "delete", + closeModal: false, + className: "swal-button--danger", + } + }, + dangerMode: true, + }) + .then((willDelete) => { + if (willDelete) { + fetch(`/user/${user}/delete`, { + credentials: 'same-origin', + method: 'post' + }).then((response) => { + return swal(`The pool for ${user} has been deleted!`, { + icon: "success", + }); + }).then(() => { + window.location = "/"; + }).catch(err => { + if (err) { + swal("Uh oh...", `Unable to delete the pool for ${user}. Please try again later.`, "error"); + } else { + swal.stopLoading(); + swal.close(); + } + }); + } + }); +}); diff --git a/templates/list_vms.html b/templates/list_vms.html index 969282b..6c8764f 100644 --- a/templates/list_vms.html +++ b/templates/list_vms.html @@ -44,6 +44,7 @@ {{ pool['user'] }} + {{ pool['num_vms'] }}
@@ -82,8 +83,11 @@ {% endif %}
- - + + + {% if not pool['vms'] %} + + {% endif %} diff --git a/templates/vm_details.html b/templates/vm_details.html index 8b0f11f..9267a83 100644 --- a/templates/vm_details.html +++ b/templates/vm_details.html @@ -20,10 +20,10 @@ {% endif %} {% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %} - {% if vm['qmpstatus'] == 'running' %} {% endif %} + {% endif %}