From 3f03d9ab69443cd694016c6dfff29d47c19b7c07 Mon Sep 17 00:00:00 2001 From: Jordan Rodgers Date: Mon, 26 Mar 2018 23:32:01 -0400 Subject: [PATCH] remove SSH tunnel and VNC stuff for deleted VMs --- proxstar/__init__.py | 12 ++++++++++++ proxstar/vnc.py | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/proxstar/__init__.py b/proxstar/__init__.py index 7e99b77..4d07a2b 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -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: diff --git a/proxstar/vnc.py b/proxstar/vnc.py index b6d06ac..5397849 100644 --- a/proxstar/vnc.py +++ b/proxstar/vnc.py @@ -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')