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.
This commit is contained in:
Will Nilges 2022-07-12 08:32:44 -04:00
parent 5332fa457c
commit 092dbe94fb
4 changed files with 1 additions and 101 deletions

View file

@ -70,11 +70,6 @@ app.config['GIT_REVISION'] = (
subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').rstrip() 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 setup
sentry_sdk.init( sentry_sdk.init(
dsn=app.config['SENTRY_DSN'], 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') logging.info('adding process expiring VMs task to scheduler')
scheduler.cron('0 5 * * *', id='process_expiring_vms', func=process_expiring_vms_task) 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: if 'cleanup_vnc' not in scheduler:
logging.info('adding cleanup VNC task to scheduler') logging.info('adding cleanup VNC task to scheduler')
scheduler.schedule( scheduler.schedule(
@ -289,15 +283,6 @@ 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):
@ -311,7 +296,6 @@ def vm_console(vmid):
) )
node = f'{vm.node}.csh.rit.edu' node = f'{vm.node}.csh.rit.edu'
token = add_vnc_target(node, vnc_port) token = add_vnc_target(node, vnc_port)
# return {'host' : node, 'port' : vnc_port, 'token' : token, 'password' : vnc_ticket}, 200
return { return {
'host': app.config['VNC_HOST'], 'host': app.config['VNC_HOST'],
'port': app.config['VNC_PORT'], 'port': app.config['VNC_PORT'],
@ -608,30 +592,6 @@ def cleanup_vnc():
return '', 200 return '', 200
print('Got bad cleanup request') print('Got bad cleanup request')
return '', 403 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/<string:template_id>/disk') @app.route('/template/<string:template_id>/disk')

View file

@ -236,8 +236,7 @@ def cleanup_vnc_task():
with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets: with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets:
targets.truncate() targets.truncate()
# FIXME (willnilges): This is straight-up not working, no matter what I try. # FIXME (willnilges): This... might be working...?
# The whole scheduling system needs a lotta work.
try: try:
requests.post( requests.post(

View file

@ -262,40 +262,6 @@ class VM:
iso = 'None' iso = 'None'
return iso 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)) @retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
def eject_iso(self): def eject_iso(self):
proxmox = connect_proxmox() proxmox = connect_proxmox()

View file

@ -120,28 +120,3 @@ def start_ssh_tunnel(node, port):
) )
server.start() server.start()
return server 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,
# )