mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +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()
|
vm.start()
|
||||||
elif action == 'stop':
|
elif action == 'stop':
|
||||||
vm.stop()
|
vm.stop()
|
||||||
stop_ssh_tunnel(vmid, ssh_tunnels)
|
send_stop_ssh_tunnel(vmid)
|
||||||
elif action == 'shutdown':
|
elif action == 'shutdown':
|
||||||
vm.shutdown()
|
vm.shutdown()
|
||||||
stop_ssh_tunnel(vmid, ssh_tunnels)
|
send_stop_ssh_tunnel(vmid)
|
||||||
elif action == 'reset':
|
elif action == 'reset':
|
||||||
vm.reset()
|
vm.reset()
|
||||||
elif action == 'suspend':
|
elif action == 'suspend':
|
||||||
|
@ -222,6 +222,15 @@ def vm_power(vmid, action):
|
||||||
return '', 403
|
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'])
|
@app.route("/console/vm/<string:vmid>", methods=['POST'])
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def vm_console(vmid):
|
def vm_console(vmid):
|
||||||
|
@ -367,7 +376,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:
|
||||||
stop_ssh_tunnel(vmid, ssh_tunnels)
|
send_stop_ssh_tunnel(vmid)
|
||||||
# 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
|
||||||
|
|
|
@ -199,6 +199,6 @@ def setup_template_task(template_id, name, user, password, cores, memory):
|
||||||
|
|
||||||
def cleanup_vnc_task():
|
def cleanup_vnc_task():
|
||||||
requests.post(
|
requests.post(
|
||||||
'https://proxstar.csh.rit.edu/console/cleanup',
|
"https://{}/console/cleanup".format(app.config['SERVER_NAME']),
|
||||||
data={'token': app.config['VNC_CLEANUP_TOKEN']},
|
data={'token': app.config['VNC_CLEANUP_TOKEN']},
|
||||||
verify=False)
|
verify=False)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
from sshtunnel import SSHTunnelForwarder
|
from sshtunnel import SSHTunnelForwarder
|
||||||
from proxstar.util import *
|
from proxstar.util import *
|
||||||
|
@ -91,9 +92,18 @@ def stop_ssh_tunnel(vmid, ssh_tunnels):
|
||||||
tunnel = next((tunnel for tunnel in ssh_tunnels
|
tunnel = next((tunnel for tunnel in ssh_tunnels
|
||||||
if tunnel.local_bind_port == port), None)
|
if tunnel.local_bind_port == port), None)
|
||||||
if tunnel:
|
if tunnel:
|
||||||
|
print("Tearing down SSH tunnel for VM {}.".format(vmid))
|
||||||
try:
|
try:
|
||||||
tunnel.stop()
|
tunnel.stop()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
ssh_tunnels.remove(tunnel)
|
ssh_tunnels.remove(tunnel)
|
||||||
delete_vnc_target(port)
|
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…
Add table
Add a link
Reference in a new issue