mirror of
				https://github.com/ComputerScienceHouse/proxstar.git
				synced 2025-03-09 15:40:09 +00:00 
			
		
		
		
	add hourly cleanup of vnc pipelines
This commit is contained in:
		
							parent
							
								
									7166650a4a
								
							
						
					
					
						commit
						e5e54d1239
					
				
					 4 changed files with 19 additions and 3 deletions
				
			
		| 
						 | 
					@ -2,6 +2,7 @@ from os import environ
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Proxstar
 | 
					# Proxstar
 | 
				
			||||||
VM_EXPIRE_MONTHS = int(environ.get('PROXSTAR_VM_EXPIRE_MONTHS', '3'))
 | 
					VM_EXPIRE_MONTHS = int(environ.get('PROXSTAR_VM_EXPIRE_MONTHS', '3'))
 | 
				
			||||||
 | 
					VNC_CLEANUP_TOKEN = environ.get('PROXSTAR_VNC_CLEANUP_TOKEN', '')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Flask
 | 
					# Flask
 | 
				
			||||||
IP = environ.get('PROXSTAR_IP', '0.0.0.0')
 | 
					IP = environ.get('PROXSTAR_IP', '0.0.0.0')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,6 +75,13 @@ if 'process_expiring_vms' not in scheduler:
 | 
				
			||||||
    scheduler.cron(
 | 
					    scheduler.cron(
 | 
				
			||||||
        '0 5 * * *', id='process_expiring_vms', func=process_expiring_vms_task)
 | 
					        '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("/")
 | 
				
			||||||
@app.route("/user/<string:user_view>")
 | 
					@app.route("/user/<string:user_view>")
 | 
				
			||||||
| 
						 | 
					@ -457,10 +464,9 @@ def allowed_users(user):
 | 
				
			||||||
        return '', 403
 | 
					        return '', 403
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.route("/console/cleanup")
 | 
					@app.route("/console/cleanup", methods=['POST'])
 | 
				
			||||||
@auth.oidc_auth
 | 
					 | 
				
			||||||
def cleanup_vnc():
 | 
					def cleanup_vnc():
 | 
				
			||||||
    if 'rtp' in session['userinfo']['groups']:
 | 
					    if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']:
 | 
				
			||||||
        for target in get_vnc_targets():
 | 
					        for target in get_vnc_targets():
 | 
				
			||||||
            tunnel = next((tunnel for tunnel in ssh_tunnels
 | 
					            tunnel = next((tunnel for tunnel in ssh_tunnels
 | 
				
			||||||
                           if tunnel.local_bind_port == int(target['port'])),
 | 
					                           if tunnel.local_bind_port == int(target['port'])),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					import requests
 | 
				
			||||||
import paramiko
 | 
					import paramiko
 | 
				
			||||||
from flask import Flask
 | 
					from flask import Flask
 | 
				
			||||||
from sqlalchemy import create_engine
 | 
					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()
 | 
					        exit_status = stdout.channel.recv_exit_status()
 | 
				
			||||||
        client.close()
 | 
					        client.close()
 | 
				
			||||||
        print("[{}] Template successfully provisioned.".format(name))
 | 
					        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)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,3 +13,4 @@ paramiko
 | 
				
			||||||
websockify
 | 
					websockify
 | 
				
			||||||
sshtunnel
 | 
					sshtunnel
 | 
				
			||||||
psutil
 | 
					psutil
 | 
				
			||||||
 | 
					requests
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue