mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-02-12 13:01:51 +00:00
send vnc teardown commands to proxstar-vnc
This commit is contained in:
parent
03baef5be0
commit
8808389b46
3 changed files with 23 additions and 4 deletions
|
@ -207,10 +207,10 @@ def vm_power(vmid, action):
|
|||
vm.start()
|
||||
elif action == 'stop':
|
||||
vm.stop()
|
||||
stop_ssh_tunnel(vmid, ssh_tunnels)
|
||||
send_stop_ssh_tunnel(vmid)
|
||||
elif action == 'shutdown':
|
||||
vm.shutdown()
|
||||
stop_ssh_tunnel(vmid, ssh_tunnels)
|
||||
send_stop_ssh_tunnel(vmid)
|
||||
elif action == 'reset':
|
||||
vm.reset()
|
||||
elif action == 'suspend':
|
||||
|
@ -222,6 +222,15 @@ def vm_power(vmid, action):
|
|||
return '', 403
|
||||
|
||||
|
||||
@app.route("/console/vm/<string:vmid>/stop", methods=['POST'])
|
||||
def vm_console_stop(vmid):
|
||||
if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']:
|
||||
stop_ssh_tunnel(vmid, ssh_tunnels)
|
||||
return '', 200
|
||||
else:
|
||||
return '', 403
|
||||
|
||||
|
||||
@app.route("/console/vm/<string:vmid>", methods=['POST'])
|
||||
@auth.oidc_auth
|
||||
def vm_console(vmid):
|
||||
|
@ -367,7 +376,7 @@ def delete(vmid):
|
|||
user = User(session['userinfo']['preferred_username'])
|
||||
proxmox = connect_proxmox()
|
||||
if user.rtp or int(vmid) in user.allowed_vms:
|
||||
stop_ssh_tunnel(vmid, ssh_tunnels)
|
||||
send_stop_ssh_tunnel(vmid)
|
||||
# Submit the delete VM task to RQ
|
||||
q.enqueue(delete_vm_task, vmid)
|
||||
return '', 200
|
||||
|
|
|
@ -199,6 +199,6 @@ def setup_template_task(template_id, name, user, password, cores, memory):
|
|||
|
||||
def cleanup_vnc_task():
|
||||
requests.post(
|
||||
'https://proxstar.csh.rit.edu/console/cleanup',
|
||||
"https://{}/console/cleanup".format(app.config['SERVER_NAME']),
|
||||
data={'token': app.config['VNC_CLEANUP_TOKEN']},
|
||||
verify=False)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import time
|
||||
import requests
|
||||
import subprocess
|
||||
from sshtunnel import SSHTunnelForwarder
|
||||
from proxstar.util import *
|
||||
|
@ -91,9 +92,18 @@ def stop_ssh_tunnel(vmid, ssh_tunnels):
|
|||
tunnel = next((tunnel for tunnel in ssh_tunnels
|
||||
if tunnel.local_bind_port == port), None)
|
||||
if tunnel:
|
||||
print("Tearing down SSH tunnel for VM {}.".format(vmid))
|
||||
try:
|
||||
tunnel.stop()
|
||||
except:
|
||||
pass
|
||||
ssh_tunnels.remove(tunnel)
|
||||
delete_vnc_target(port)
|
||||
|
||||
|
||||
def send_stop_ssh_tunnel(vmid):
|
||||
requests.post(
|
||||
"https://{}/console/vm/{}/stop".format(app.config['SERVER_NAME'],
|
||||
vmid),
|
||||
data={'token': app.config['VNC_CLEANUP_TOKEN']},
|
||||
verify=False)
|
||||
|
|
Loading…
Reference in a new issue