mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
teardown ssh/vnc stuff after shutdown and reset requests
This commit is contained in:
parent
3f03d9ab69
commit
03baef5be0
2 changed files with 17 additions and 11 deletions
|
@ -207,8 +207,10 @@ def vm_power(vmid, action):
|
||||||
vm.start()
|
vm.start()
|
||||||
elif action == 'stop':
|
elif action == 'stop':
|
||||||
vm.stop()
|
vm.stop()
|
||||||
|
stop_ssh_tunnel(vmid, ssh_tunnels)
|
||||||
elif action == 'shutdown':
|
elif action == 'shutdown':
|
||||||
vm.shutdown()
|
vm.shutdown()
|
||||||
|
stop_ssh_tunnel(vmid, ssh_tunnels)
|
||||||
elif action == 'reset':
|
elif action == 'reset':
|
||||||
vm.reset()
|
vm.reset()
|
||||||
elif action == 'suspend':
|
elif action == 'suspend':
|
||||||
|
@ -365,17 +367,7 @@ def delete(vmid):
|
||||||
user = User(session['userinfo']['preferred_username'])
|
user = User(session['userinfo']['preferred_username'])
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user.rtp or int(vmid) in user.allowed_vms:
|
if user.rtp or int(vmid) in user.allowed_vms:
|
||||||
# Tear down the SSH tunnel and VNC stuff for the VM
|
stop_ssh_tunnel(vmid, ssh_tunnels)
|
||||||
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
|
# Submit the delete VM task to RQ
|
||||||
q.enqueue(delete_vm_task, vmid)
|
q.enqueue(delete_vm_task, vmid)
|
||||||
return '', 200
|
return '', 200
|
||||||
|
|
|
@ -83,3 +83,17 @@ def start_ssh_tunnel(node, port):
|
||||||
local_bind_address=('127.0.0.1', port))
|
local_bind_address=('127.0.0.1', port))
|
||||||
server.start()
|
server.start()
|
||||||
return server
|
return server
|
||||||
|
|
||||||
|
|
||||||
|
def stop_ssh_tunnel(vmid, ssh_tunnels):
|
||||||
|
# Tear down the SSH tunnel and VNC target entry for a given 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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue