remove SSH tunnel and VNC stuff for deleted VMs

This commit is contained in:
Jordan Rodgers 2018-03-26 23:32:01 -04:00
parent e608c0dc10
commit 3f03d9ab69
2 changed files with 14 additions and 2 deletions

View file

@ -365,6 +365,18 @@ def delete(vmid):
user = User(session['userinfo']['preferred_username'])
proxmox = connect_proxmox()
if user.rtp or int(vmid) in user.allowed_vms:
# Tear down the SSH tunnel and VNC stuff for the VM
port = 5900 + int(vmid)
tunnel = next((tunnel for tunnel in ssh_tunnels
if tunnel.local_bind_port == port), None)
if tunnel:
try:
tunnel.stop()
except:
pass
ssh_tunnels.remove(tunnel)
delete_vnc_target(port)
# Submit the delete VM task to RQ
q.enqueue(delete_vm_task, vmid)
return '', 200
else:

View file

@ -62,8 +62,8 @@ def add_vnc_target(port):
def delete_vnc_target(port):
targets = get_vnc_targets()
target = next((target for target in targets if target['port'] == port),
None)
target = next(
(target for target in targets if target['port'] == str(port)), None)
if target:
targets.remove(target)
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w')