mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
add proxmox vnc command, check if targets file exists before retrieving entries
This commit is contained in:
parent
58863732af
commit
3b1740c641
4 changed files with 27 additions and 16 deletions
|
@ -53,5 +53,7 @@ REDIS_HOST = environ.get('PROXSTAR_REDIS_HOST', 'localhost')
|
|||
REDIS_PORT = int(environ.get('PROXSTAR_REDIS_PORT', '6379'))
|
||||
|
||||
# VNC
|
||||
WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH', '/opt/app-root/bin/websockify')
|
||||
WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE', '/opt/app-root/src/targets')
|
||||
WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH',
|
||||
'/opt/app-root/bin/websockify')
|
||||
WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE',
|
||||
'/opt/app-root/src/targets')
|
||||
|
|
|
@ -33,7 +33,8 @@ app.config["GIT_REVISION"] = subprocess.check_output(
|
|||
with open('proxmox_ssh_key', 'w') as key:
|
||||
key.write(app.config['PROXMOX_SSH_KEY'])
|
||||
|
||||
start_websockify(app.config['WEBSOCKIFY_PATH'], app.config['WEBSOCKIFY_TARGET_FILE'])
|
||||
start_websockify(app.config['WEBSOCKIFY_PATH'],
|
||||
app.config['WEBSOCKIFY_TARGET_FILE'])
|
||||
|
||||
ssh_tunnels = []
|
||||
|
||||
|
@ -196,6 +197,7 @@ def vm_console(vmid):
|
|||
rtp = 'rtp' in session['userinfo']['groups']
|
||||
proxmox = connect_proxmox()
|
||||
if rtp or int(vmid) in get_user_allowed_vms(proxmox, db, user):
|
||||
start_vm_vnc(proxmox, vmid)
|
||||
port = str(5900 + int(vmid))
|
||||
token = add_vnc_target(port)
|
||||
node = "{}.csh.rit.edu".format(get_vm_node(proxmox, vmid))
|
||||
|
@ -464,6 +466,5 @@ def exit_handler():
|
|||
|
||||
atexit.register(exit_handler)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
|
|
@ -259,6 +259,13 @@ def change_vm_mem(proxmox, vmid, mem):
|
|||
node.qemu(vmid).config.put(memory=mem)
|
||||
|
||||
|
||||
def start_vm_vnc(proxmox, vmid):
|
||||
node = proxmox.nodes(get_vm_node(proxmox, vmid))
|
||||
port = str(5900 + int(vmid))
|
||||
node.qemu(vmid).monitor.post(
|
||||
command="change vnc 127.0.0.1:{}".format(port))
|
||||
|
||||
|
||||
def get_isos(proxmox, storage):
|
||||
isos = []
|
||||
for iso in proxmox.nodes('proxmox01').storage(storage).content.get():
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import time
|
||||
import subprocess
|
||||
from sshtunnel import SSHTunnelForwarder
|
||||
|
@ -10,9 +11,8 @@ def start_websockify(websockify_path, target_file):
|
|||
if not result.stdout:
|
||||
subprocess.call(
|
||||
[
|
||||
websockify_path, '8081', '--token-plugin',
|
||||
'TokenFile', '--token-source', target_file,
|
||||
'-D'
|
||||
websockify_path, '8081', '--token-plugin', 'TokenFile',
|
||||
'--token-source', target_file, '-D'
|
||||
],
|
||||
stdout=subprocess.PIPE)
|
||||
|
||||
|
@ -33,16 +33,17 @@ def stop_websockify():
|
|||
|
||||
|
||||
def get_vnc_targets():
|
||||
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'])
|
||||
targets = []
|
||||
for line in target_file:
|
||||
target_dict = dict()
|
||||
values = line.strip().split(':')
|
||||
target_dict['token'] = values[0]
|
||||
target_dict['port'] = values[2]
|
||||
targets.append(target_dict)
|
||||
target_file.close()
|
||||
return (targets)
|
||||
if os.path.exists(app.config['WEBSOCKIFY_TARGET_FILE']):
|
||||
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'])
|
||||
for line in target_file:
|
||||
target_dict = dict()
|
||||
values = line.strip().split(':')
|
||||
target_dict['token'] = values[0]
|
||||
target_dict['port'] = values[2]
|
||||
targets.append(target_dict)
|
||||
target_file.close()
|
||||
return targets
|
||||
|
||||
|
||||
def add_vnc_target(port):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue