From 092dbe94fb5dd3d2ce6c09bb58cfc42e2be4a2d5 Mon Sep 17 00:00:00 2001 From: Will Nilges Date: Tue, 12 Jul 2022 08:32:44 -0400 Subject: [PATCH] Remove obviously dead code There's still some code in here that may require more careful extraction, testing, and review, so I'm saving that for another PR. --- proxstar/__init__.py | 40 ---------------------------------------- proxstar/tasks.py | 3 +-- proxstar/vm.py | 34 ---------------------------------- proxstar/vnc.py | 25 ------------------------- 4 files changed, 1 insertion(+), 101 deletions(-) diff --git a/proxstar/__init__.py b/proxstar/__init__.py index b0a48af..d3c1d6e 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -70,11 +70,6 @@ app.config['GIT_REVISION'] = ( subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').rstrip() ) -# Probably cursed. -# if 'localhost' in app.config['SERVER_NAME']: -# print('Server name is localhost. Starting websockify...') -# start_websockify(app.config['WEBSOCKIFY_PATH'], app.config['WEBSOCKIFY_TARGET_FILE']) - # Sentry setup sentry_sdk.init( dsn=app.config['SENTRY_DSN'], @@ -133,7 +128,6 @@ if 'process_expiring_vms' not in scheduler: logging.info('adding process expiring VMs task to scheduler') scheduler.cron('0 5 * * *', id='process_expiring_vms', func=process_expiring_vms_task) -# FIXME (willnilges): is this operating in the right container? if 'cleanup_vnc' not in scheduler: logging.info('adding cleanup VNC task to scheduler') scheduler.schedule( @@ -289,15 +283,6 @@ def vm_power(vmid, action): return '', 403 -# @app.route('/console/vm//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/', methods=['POST']) @auth.oidc_auth def vm_console(vmid): @@ -311,7 +296,6 @@ def vm_console(vmid): ) node = f'{vm.node}.csh.rit.edu' token = add_vnc_target(node, vnc_port) - # return {'host' : node, 'port' : vnc_port, 'token' : token, 'password' : vnc_ticket}, 200 return { 'host': app.config['VNC_HOST'], 'port': app.config['VNC_PORT'], @@ -608,30 +592,6 @@ def cleanup_vnc(): return '', 200 print('Got bad cleanup request') return '', 403 - # 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'])), - # None, - # ) - # if tunnel: - # if not next( - # ( - # conn - # for conn in psutil.net_connections() - # if conn.laddr[1] == int(target['port']) and conn.status == 'ESTABLISHED' - # ), - # None, - # ): - # try: - # tunnel.stop() - # except: - # pass - # ssh_tunnels.remove(tunnel) - # delete_vnc_target(target['port']) - # return '', 200 - # else: - # return '', 403 @app.route('/template//disk') diff --git a/proxstar/tasks.py b/proxstar/tasks.py index d04caf7..7b47dac 100644 --- a/proxstar/tasks.py +++ b/proxstar/tasks.py @@ -236,8 +236,7 @@ def cleanup_vnc_task(): with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets: targets.truncate() - # FIXME (willnilges): This is straight-up not working, no matter what I try. - # The whole scheduling system needs a lotta work. + # FIXME (willnilges): This... might be working...? try: requests.post( diff --git a/proxstar/vm.py b/proxstar/vm.py index f0cde27..30624a0 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -262,40 +262,6 @@ class VM: iso = 'None' return iso - # def start_vnc(self, port): - # proxmox = connect_proxmox() - # port = str(int(port) - 5900) - # proxmox.nodes(self.node).qemu(self.id).monitor.post( - # command='change vnc 127.0.0.1:{}'.format(port) - # ) - - # def configure_vnc_in_vm_config(): # self, ssh_user, ssh_pass): - # """Sets the vm up for VNC. Enables it to open a socket on localhost - # with a pre-determined password, which proxstar can then proxy to a noVNC - # instance. - # FIXME (willnilges): Dead Code. Remove this function. - # """ - # proxmox = connect_proxmox() - # config = f'args: -object secret,id=secvnc{self.id},data={self.id} -vnc - # 127.0.0.1:{int(self.id)+5900},password-secret=secvnc{self.id}' - # path = f'/etc/pve/local/qemu-server/{self.id}.conf' - # with paramiko.SSHClient() as ssh: - # ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - # ssh.connect( - # self.node, - # port=22, - # username=ssh_user, - # key_filename='proxmox_ssh_key', - # passphrase=ssh_pass, - # ) - # ssh.exec_command( - # f"if grep -- '{config}' {path}; then echo identical config found; - # else sed -i /dev/null '/-vnc/d' {path}" - # ) # YOLO - # ssh.exec_command( - # f"if grep -- '-vnc' {path}; then echo found config; else echo {config} >> {path}; fi" - # ) - @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) def eject_iso(self): proxmox = connect_proxmox() diff --git a/proxstar/vnc.py b/proxstar/vnc.py index 6773d78..8d9180e 100644 --- a/proxstar/vnc.py +++ b/proxstar/vnc.py @@ -120,28 +120,3 @@ def start_ssh_tunnel(node, port): ) server.start() return server - - -# def stop_ssh_tunnel(): # vmid, ssh_tunnels): -# # FIXME (willnilges): Dead code. Delete this function. -# # Tear down the SSH tunnel and VNC target entry for a given VM -# print(f'This code is useless') -# pass -# port = 5900 + int(vmid) -# tunnel = next((tunnel for tunnel in ssh_tunnels if tunnel.local_bind_port == port), None) -# if tunnel: -# logging.info('tearing down SSH tunnel for VM %s', 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, -# )