mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-02-14 22:11:51 +00:00
I'm starting to understand
I don't know if any of this will be useful, but it's a start.
This commit is contained in:
parent
cb077f5a93
commit
608319c9ad
4 changed files with 42 additions and 11 deletions
|
@ -12,7 +12,7 @@ from redis import Redis
|
|||
from rq_scheduler import Scheduler
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from flask import Flask, render_template, request, redirect, session, abort, url_for, jsonify
|
||||
from flask import Flask, render_template, request, redirect, session, abort, url_for, jsonify, Response
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||
from sentry_sdk.integrations.rq import RqIntegration
|
||||
|
@ -151,7 +151,6 @@ def forbidden(e):
|
|||
user = User(session['userinfo']['preferred_username'])
|
||||
return render_template('403.html', user=user, e=e), 403
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/user/<string:user_view>')
|
||||
@auth.oidc_auth
|
||||
|
@ -285,12 +284,25 @@ def vm_console(vmid):
|
|||
node = '{}.csh.rit.edu'.format(vm.node)
|
||||
logging.info('creating SSH tunnel to %s for VM %s', node, vm.id)
|
||||
tunnel = start_ssh_tunnel(node, port)
|
||||
vm.configure_vnc_in_vm_config(app.config['PROXMOX_SSH_USER'], app.config['PROXMOX_SSH_KEY_PASS'])
|
||||
ssh_tunnels.append(tunnel)
|
||||
vm.start_vnc(port)
|
||||
# vm.start_vnc(port) # Broken :(
|
||||
return token, 200
|
||||
else:
|
||||
return '', 403
|
||||
|
||||
@app.route('/novnc')
|
||||
def get_resource(): # pragma: no cover
|
||||
mimetypes = {
|
||||
".css": "text/css",
|
||||
".html": "text/html",
|
||||
".js": "application/javascript",
|
||||
}
|
||||
complete_path = os.path.join('/opt/proxstar/proxstar/', 'static/noVNC/vnc.html')
|
||||
# ext = os.path.splitext(path)[1]
|
||||
# mimetype = mimetypes.get(ext, "text/html")
|
||||
content = open(complete_path).read()
|
||||
return Response(content)
|
||||
|
||||
@app.route('/vm/<string:vmid>/cpu/<int:cores>', methods=['POST'])
|
||||
@auth.oidc_auth
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import json
|
||||
from sqlite3 import connect
|
||||
import urllib
|
||||
|
||||
from flask import current_app as app
|
||||
from tenacity import retry, stop_after_attempt, wait_fixed
|
||||
from paramiko import SSHClient
|
||||
|
||||
from proxstar import db, starrs
|
||||
from proxstar.db import delete_vm_expire, get_vm_expire
|
||||
|
@ -262,12 +264,27 @@ 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 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.
|
||||
|
||||
TODO (willnilges): Current password is "chomchom1", but should be changed lol
|
||||
"""
|
||||
# proxmox = connect_proxmox()
|
||||
config = f'args: -object secret,id=secvnc{self.id},data=chomchom1 -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 SSHClient() as ssh:
|
||||
ssh.connect(self.node, port=22, username=ssh_user, key_filename='proxmox_ssh_key', passphrase=ssh_pass)
|
||||
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):
|
||||
|
|
|
@ -62,6 +62,9 @@ def delete_vnc_target(port):
|
|||
|
||||
|
||||
def start_ssh_tunnel(node, port):
|
||||
"""Forwards a port on a node
|
||||
to the proxstar container
|
||||
"""
|
||||
port = int(port)
|
||||
server = SSHTunnelForwarder(
|
||||
node,
|
||||
|
@ -74,7 +77,6 @@ def start_ssh_tunnel(node, port):
|
|||
server.start()
|
||||
return server
|
||||
|
||||
|
||||
def stop_ssh_tunnel(vmid, ssh_tunnels):
|
||||
# Tear down the SSH tunnel and VNC target entry for a given VM
|
||||
port = 5900 + int(vmid)
|
||||
|
|
|
@ -7,7 +7,7 @@ jinja2==2.11.3
|
|||
flask-pyoidc==1.3.0
|
||||
gunicorn==20.0.4
|
||||
markupsafe==2.0.1
|
||||
paramiko==2.7.2
|
||||
paramiko==2.11.0
|
||||
proxmoxer==1.1.1
|
||||
psutil==5.8.0
|
||||
psycopg2-binary==2.9.3
|
||||
|
|
Loading…
Reference in a new issue