1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 03:54:15 +00:00
webvirtcloud/console/views.py

53 lines
1.8 KiB
Python
Raw Normal View History

2015-02-27 12:25:41 +00:00
import re
from django.shortcuts import render
2020-04-24 16:34:29 +00:00
from libvirt import libvirtError
2015-02-27 12:25:41 +00:00
from instances.models import Instance
from vrtManager.instance import wvmInstance
from webvirtcloud.settings import WS_PUBLIC_PORT, WS_PUBLIC_HOST
2015-02-27 12:25:41 +00:00
def console(request):
"""
:param request:
:return:
"""
2018-05-31 09:38:03 +00:00
console_error = None
2015-02-27 12:25:41 +00:00
if request.method == 'GET':
token = request.GET.get('token', '')
view_type = request.GET.get('view', 'lite')
2015-02-27 12:25:41 +00:00
try:
temptoken = token.split('-', 1)
host = int(temptoken[0])
uuid = temptoken[1]
instance = Instance.objects.get(compute_id=host, uuid=uuid)
conn = wvmInstance(instance.compute.hostname,
instance.compute.login,
instance.compute.password,
instance.compute.type,
instance.name)
console_type = conn.get_console_type()
console_websocket_port = conn.get_console_websocket_port()
console_passwd = conn.get_console_passwd()
except libvirtError:
2015-02-27 12:25:41 +00:00
console_type = None
console_websocket_port = None
console_passwd = None
2019-11-08 17:07:02 +00:00
ws_port = console_websocket_port if console_websocket_port else WS_PUBLIC_PORT
2015-02-27 12:25:41 +00:00
ws_host = WS_PUBLIC_HOST if WS_PUBLIC_HOST else request.get_host()
if ':' in ws_host:
ws_host = re.sub(':[0-9]+', '', ws_host)
console_page = "console-" + console_type + "-" + view_type + ".html"
if console_type == 'vnc' or console_type == 'spice':
response = render(request, console_page, locals())
2015-02-27 12:25:41 +00:00
else:
console_error = f"Console type: {console_type} no support"
response = render(request, 'console-vnc-lite.html', locals())
2015-02-27 12:25:41 +00:00
response.set_cookie('token', token)
return response