add hourly cleanup of vnc pipelines

This commit is contained in:
Jordan Rodgers 2018-02-20 02:01:33 -05:00
parent 7166650a4a
commit e5e54d1239
4 changed files with 19 additions and 3 deletions

View file

@ -2,6 +2,7 @@ from os import environ
# Proxstar
VM_EXPIRE_MONTHS = int(environ.get('PROXSTAR_VM_EXPIRE_MONTHS', '3'))
VNC_CLEANUP_TOKEN = environ.get('PROXSTAR_VNC_CLEANUP_TOKEN', '')
# Flask
IP = environ.get('PROXSTAR_IP', '0.0.0.0')

View file

@ -75,6 +75,13 @@ if 'process_expiring_vms' not in scheduler:
scheduler.cron(
'0 5 * * *', id='process_expiring_vms', func=process_expiring_vms_task)
if 'cleanup_vnc' not in scheduler:
scheduler.schedule(
id='cleanup_vnc',
scheduled_time=datetime.datetime.utcnow(),
func=cleanup_vnc_task,
interval=3600)
@app.route("/")
@app.route("/user/<string:user_view>")
@ -457,10 +464,9 @@ def allowed_users(user):
return '', 403
@app.route("/console/cleanup")
@auth.oidc_auth
@app.route("/console/cleanup", methods=['POST'])
def cleanup_vnc():
if 'rtp' in session['userinfo']['groups']:
if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']:
for target in get_vnc_targets():
tunnel = next((tunnel for tunnel in ssh_tunnels
if tunnel.local_bind_port == int(target['port'])),

View file

@ -1,4 +1,5 @@
import os
import requests
import paramiko
from flask import Flask
from sqlalchemy import create_engine
@ -161,3 +162,10 @@ def setup_template(template_id, name, user, password, cores, memory):
exit_status = stdout.channel.recv_exit_status()
client.close()
print("[{}] Template successfully provisioned.".format(name))
def cleanup_vnc_task():
requests.post(
'https://proxstar.csh.rit.edu/console/cleanup',
data={'token': app.config['VNC_CLEANUP_TOKEN']},
verify=False)

View file

@ -13,3 +13,4 @@ paramiko
websockify
sshtunnel
psutil
requests