Hype-2/functions/fvnc.py

28 lines
903 B
Python
Raw Normal View History

2023-10-17 08:03:51 +00:00
from config import *
from xml.etree import ElementTree as ET
from flask import request, Response
2024-04-22 14:54:48 +00:00
import subprocess
2023-10-17 08:03:51 +00:00
import os
def get_vnc_port(vm_name):
dom = conn.lookupByName(vm_name)
vm_xml = dom.XMLDesc(0)
et_xml = ET.fromstring(vm_xml)
graphics = et_xml.find('./devices/graphics')
vnc_port = graphics.get('port')
return vnc_port
def kill_consoles():
2024-04-22 14:54:48 +00:00
subprocess.run("pkill -9 -f 'websockify'", shell=True)
subprocess.run("for i in $(pgrep -f 'pyxterm'); do kill -9 $i; done", shell=True)
2023-10-17 08:03:51 +00:00
def socket_connect(vm_name):
kill_consoles()
vm_port = get_vnc_port(vm_name)
2024-04-22 14:54:48 +00:00
subprocess.run(['websockify', '-D', '--web=/usr/share/novnc/', '6080', 'localhost:' + vm_port])
2023-10-17 08:03:51 +00:00
2023-10-18 10:21:48 +00:00
def pyxterm_connect(path,lxc_name):
2023-10-17 08:03:51 +00:00
kill_consoles()
2024-04-22 14:54:48 +00:00
cmd = ['python3', f'{path}/pyxterm.py', '--command', 'lxc-attach', '--cmd-args', lxc_name]
pyx_process = subprocess.Popen(cmd)