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'))
|
REDIS_PORT = int(environ.get('PROXSTAR_REDIS_PORT', '6379'))
|
||||||
|
|
||||||
# VNC
|
# VNC
|
||||||
WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH', '/opt/app-root/bin/websockify')
|
WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH',
|
||||||
WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE', '/opt/app-root/src/targets')
|
'/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:
|
with open('proxmox_ssh_key', 'w') as key:
|
||||||
key.write(app.config['PROXMOX_SSH_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 = []
|
ssh_tunnels = []
|
||||||
|
|
||||||
|
@ -196,6 +197,7 @@ def vm_console(vmid):
|
||||||
rtp = 'rtp' in session['userinfo']['groups']
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if rtp or int(vmid) in get_user_allowed_vms(proxmox, db, user):
|
if rtp or int(vmid) in get_user_allowed_vms(proxmox, db, user):
|
||||||
|
start_vm_vnc(proxmox, vmid)
|
||||||
port = str(5900 + int(vmid))
|
port = str(5900 + int(vmid))
|
||||||
token = add_vnc_target(port)
|
token = add_vnc_target(port)
|
||||||
node = "{}.csh.rit.edu".format(get_vm_node(proxmox, vmid))
|
node = "{}.csh.rit.edu".format(get_vm_node(proxmox, vmid))
|
||||||
|
@ -464,6 +466,5 @@ def exit_handler():
|
||||||
|
|
||||||
atexit.register(exit_handler)
|
atexit.register(exit_handler)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run()
|
||||||
|
|
|
@ -259,6 +259,13 @@ def change_vm_mem(proxmox, vmid, mem):
|
||||||
node.qemu(vmid).config.put(memory=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):
|
def get_isos(proxmox, storage):
|
||||||
isos = []
|
isos = []
|
||||||
for iso in proxmox.nodes('proxmox01').storage(storage).content.get():
|
for iso in proxmox.nodes('proxmox01').storage(storage).content.get():
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
from sshtunnel import SSHTunnelForwarder
|
from sshtunnel import SSHTunnelForwarder
|
||||||
|
@ -10,9 +11,8 @@ def start_websockify(websockify_path, target_file):
|
||||||
if not result.stdout:
|
if not result.stdout:
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
[
|
[
|
||||||
websockify_path, '8081', '--token-plugin',
|
websockify_path, '8081', '--token-plugin', 'TokenFile',
|
||||||
'TokenFile', '--token-source', target_file,
|
'--token-source', target_file, '-D'
|
||||||
'-D'
|
|
||||||
],
|
],
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
@ -33,8 +33,9 @@ def stop_websockify():
|
||||||
|
|
||||||
|
|
||||||
def get_vnc_targets():
|
def get_vnc_targets():
|
||||||
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'])
|
|
||||||
targets = []
|
targets = []
|
||||||
|
if os.path.exists(app.config['WEBSOCKIFY_TARGET_FILE']):
|
||||||
|
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'])
|
||||||
for line in target_file:
|
for line in target_file:
|
||||||
target_dict = dict()
|
target_dict = dict()
|
||||||
values = line.strip().split(':')
|
values = line.strip().split(':')
|
||||||
|
@ -42,7 +43,7 @@ def get_vnc_targets():
|
||||||
target_dict['port'] = values[2]
|
target_dict['port'] = values[2]
|
||||||
targets.append(target_dict)
|
targets.append(target_dict)
|
||||||
target_file.close()
|
target_file.close()
|
||||||
return (targets)
|
return targets
|
||||||
|
|
||||||
|
|
||||||
def add_vnc_target(port):
|
def add_vnc_target(port):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue