mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
rework console so migrating vms isnt dumb and ssh tunnels can be torn down
This commit is contained in:
parent
08821b0b75
commit
f84b205f15
3 changed files with 27 additions and 11 deletions
|
@ -68,7 +68,7 @@ if 'generate_pool_cache' not in scheduler:
|
|||
id='generate_pool_cache',
|
||||
scheduled_time=datetime.datetime.utcnow(),
|
||||
func=generate_pool_cache_task,
|
||||
interval=60)
|
||||
interval=90)
|
||||
|
||||
if 'process_expiring_vms' not in scheduler:
|
||||
scheduler.cron(
|
||||
|
@ -176,7 +176,7 @@ def vm_power(vmid, action):
|
|||
return '', 403
|
||||
|
||||
|
||||
@app.route("/vm/<string:vmid>/console", methods=['POST'])
|
||||
@app.route("/console/vm/<string:vmid>", methods=['POST'])
|
||||
@auth.oidc_auth
|
||||
def vm_console(vmid):
|
||||
user = build_user_dict(session, db)
|
||||
|
@ -186,13 +186,28 @@ def vm_console(vmid):
|
|||
port = str(5900 + int(vmid))
|
||||
token = add_vnc_target(port)
|
||||
node = "{}.csh.rit.edu".format(get_vm_node(proxmox, vmid))
|
||||
print("Creating SSH tunnel to {} for VM {}.".format(node, vmid))
|
||||
try:
|
||||
tunnel = next((tunnel for tunnel in ssh_tunnels
|
||||
if tunnel.local_bind_port == int(port)), None)
|
||||
if tunnel:
|
||||
if tunnel.ssh_host != node:
|
||||
print(
|
||||
"Tunnel already exists for VM {} to the wrong Proxmox node.".
|
||||
format(vmid))
|
||||
tunnel.stop()
|
||||
ssh_tunnels.remove(tunnel)
|
||||
print("Creating SSH tunnel to {} for VM {}.".format(
|
||||
node, vmid))
|
||||
tunnel = start_ssh_tunnel(node, port)
|
||||
ssh_tunnels.append(tunnel)
|
||||
start_vm_vnc(proxmox, vmid, port)
|
||||
else:
|
||||
print("Tunnel already exists to {} for VM {}.".format(
|
||||
node, vmid))
|
||||
else:
|
||||
print("Creating SSH tunnel to {} for VM {}.".format(node, vmid))
|
||||
tunnel = start_ssh_tunnel(node, port)
|
||||
ssh_tunnels.append(tunnel)
|
||||
except:
|
||||
print('SSH tunnel already exists.')
|
||||
start_vm_vnc(proxmox, vmid)
|
||||
start_vm_vnc(proxmox, vmid, port)
|
||||
return token, 200
|
||||
else:
|
||||
return '', 403
|
||||
|
|
|
@ -25,7 +25,7 @@ def get_vms_for_user(proxmox, db, user):
|
|||
pools = get_pools(proxmox, db)
|
||||
if user not in pools:
|
||||
if is_user(user) and not is_rtp(user):
|
||||
proxmox.pools.post(poolid=user, comment='Managed by Proxstar')
|
||||
proxmox.pools.post(poolid=user, comment='Managed by Proxstar')
|
||||
else:
|
||||
return []
|
||||
vms = proxmox.pools(user).get()['members']
|
||||
|
@ -253,10 +253,11 @@ def change_vm_mem(proxmox, vmid, mem):
|
|||
node.qemu(vmid).config.put(memory=mem)
|
||||
|
||||
|
||||
def start_vm_vnc(proxmox, vmid):
|
||||
def start_vm_vnc(proxmox, vmid, port):
|
||||
node = proxmox.nodes(get_vm_node(proxmox, vmid))
|
||||
port = str(int(port) - 5900)
|
||||
node.qemu(vmid).monitor.post(
|
||||
command="change vnc 127.0.0.1:{}".format(vmid))
|
||||
command="change vnc 127.0.0.1:{}".format(port))
|
||||
|
||||
|
||||
def get_isos(proxmox, storage):
|
||||
|
|
|
@ -808,7 +808,7 @@ function hide_for_template(obj) {
|
|||
$("#console-vm").click(function(){
|
||||
const vmname = $(this).data('vmname');
|
||||
const vmid = $(this).data('vmid');
|
||||
fetch(`/vm/${vmid}/console`, {
|
||||
fetch(`https://proxstar-vnc.csh.rit.edu/console/vm/${vmid}`, {
|
||||
credentials: 'same-origin',
|
||||
method: 'post'
|
||||
}).then((response) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue