mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
add agent, add ability to delete user/pool, change order of power buttons
This commit is contained in:
parent
125fd58b27
commit
8161d97f21
7 changed files with 85 additions and 10 deletions
5
agent.py
Normal file
5
agent.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from websockify.websocket import *
|
||||||
|
from websockify.websocketproxy import *
|
||||||
|
|
||||||
|
server = WebSocketProxy(listen_port='10000', target_port='6000')
|
||||||
|
server.start_server()
|
20
app.py
20
app.py
|
@ -27,6 +27,7 @@ cache = SimpleCache()
|
||||||
def list_vms(user=None):
|
def list_vms(user=None):
|
||||||
rtp_view = False
|
rtp_view = False
|
||||||
rtp = 'rtp' in session['userinfo']['groups']
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
|
active = 'active' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user and not rtp:
|
if user and not rtp:
|
||||||
return '', 403
|
return '', 403
|
||||||
|
@ -45,7 +46,12 @@ def list_vms(user=None):
|
||||||
user = session['userinfo']['preferred_username']
|
user = session['userinfo']['preferred_username']
|
||||||
vms = get_vms_for_user(proxmox, user)
|
vms = get_vms_for_user(proxmox, user)
|
||||||
return render_template(
|
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")
|
@app.route("/isos")
|
||||||
|
@ -304,6 +310,18 @@ def reset_limits(user):
|
||||||
return '', 403
|
return '', 403
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/user/<string: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/<string:vmid>/rrd/<path:path>')
|
@app.route('/vm/<string:vmid>/rrd/<path:path>')
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def send_rrd(vmid, path):
|
def send_rrd(vmid, path):
|
||||||
|
|
11
proxmox.py
11
proxmox.py
|
@ -36,6 +36,8 @@ def get_vms_for_rtp(proxmox):
|
||||||
for pool in pools:
|
for pool in pools:
|
||||||
pool_dict = dict()
|
pool_dict = dict()
|
||||||
pool_dict['user'] = pool
|
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['usage'] = get_user_usage(proxmox, pool)
|
||||||
pool_dict['limits'] = get_user_usage_limits(pool)
|
pool_dict['limits'] = get_user_usage_limits(pool)
|
||||||
pool_dict['percents'] = get_user_usage_percent(
|
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))
|
node = proxmox.nodes(get_vm_node(proxmox, vmid))
|
||||||
image = node.qemu(vmid).rrd.get(ds=source, timeframe=time)['image']
|
image = node.qemu(vmid).rrd.get(ds=source, timeframe=time)['image']
|
||||||
return 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()
|
||||||
|
|
|
@ -90,10 +90,9 @@ table, th, td {
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.proxstar-limitbtn {
|
.proxstar-poolbtn {
|
||||||
padding-top: 0px;
|
padding: 0;
|
||||||
padding-bottom: 0px;
|
width: 55px;
|
||||||
width: 70px;
|
|
||||||
height: 25px;
|
height: 25px;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -654,7 +654,7 @@ $(".edit-limit").click(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
window.location = `/limits`;
|
window.location = "/";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
@ -692,7 +692,7 @@ $(".reset-limit").click(function(){
|
||||||
icon: "success",
|
icon: "success",
|
||||||
});
|
});
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
window.location = `/limits`;
|
window.location = "/";
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
swal("Uh oh...", `Unable to reset the usage limits for ${user}. Please try again later.`, "error");
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
{{ pool['user'] }}
|
{{ pool['user'] }}
|
||||||
</a>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
<span class="pull-right">{{ pool['num_vms'] }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="resource-bar">
|
<div class="resource-bar">
|
||||||
|
@ -82,8 +83,11 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-info proxstar-limitbtn edit-limit" data-user="{{ pool['user'] }}" data-cpu="{{ pool['limits']['cpu'] }}" data-mem="{{ pool['limits']['mem'] }}" data-disk="{{ pool['limits']['disk'] }}">EDIT</button>
|
<button class="btn btn-info proxstar-poolbtn edit-limit" data-user="{{ pool['user'] }}" data-cpu="{{ pool['limits']['cpu'] }}" data-mem="{{ pool['limits']['mem'] }}" data-disk="{{ pool['limits']['disk'] }}">EDIT</button>
|
||||||
<button class="btn btn-danger proxstar-limitbtn reset-limit" data-user="{{ pool['user'] }}">RESET</button>
|
<button class="btn btn-warning proxstar-poolbtn reset-limit" data-user="{{ pool['user'] }}">RESET</button>
|
||||||
|
{% if not pool['vms'] %}
|
||||||
|
<button class="btn btn-danger proxstar-poolbtn delete-user" data-user="{{ pool['user'] }}">DELETE</button>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
<button class="btn btn-success proxstar-actionbtn" id="resume-vm" name="resume" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">RESUME</button>
|
<button class="btn btn-success proxstar-actionbtn" id="resume-vm" name="resume" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">RESUME</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %}
|
{% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %}
|
||||||
<button class="btn btn-info proxstar-actionbtn" id="shutdown-vm" name="shutdown" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">SHUTDOWN</button>
|
|
||||||
{% if vm['qmpstatus'] == 'running' %}
|
{% if vm['qmpstatus'] == 'running' %}
|
||||||
<button class="btn btn-info proxstar-actionbtn" id="suspend-vm" name="suspend" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">SUSPEND</button>
|
<button class="btn btn-info proxstar-actionbtn" id="suspend-vm" name="suspend" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">SUSPEND</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<button class="btn btn-info proxstar-actionbtn" id="shutdown-vm" name="shutdown" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">SHUTDOWN</button>
|
||||||
<button class="btn btn-warning proxstar-actionbtn" id="stop-vm" name="stop" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">STOP</button>
|
<button class="btn btn-warning proxstar-actionbtn" id="stop-vm" name="stop" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">STOP</button>
|
||||||
<button class="btn btn-warning proxstar-actionbtn" id="reset-vm" name="reset" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">RESET</button>
|
<button class="btn btn-warning proxstar-actionbtn" id="reset-vm" name="reset" data-vmid="{{ vm['vmid'] }}" data-vmname="{{ vm['name'] }}">RESET</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue