1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

add vdiconsole datasource endpoint. provides vdi url for remote-viewer.

add instance/access/vdi panel
This commit is contained in:
Ing. Jan KRCMAR 2018-06-21 14:53:35 +02:00
parent 27a7a7a365
commit 464e7bee39
3 changed files with 46 additions and 0 deletions

View file

@ -1,6 +1,9 @@
from django.shortcuts import render
from django.http import HttpResponse, Http404
from accounts.models import UserInstance, UserSSHKey
from instances.models import Instance
from vrtManager.instance import wvmInstance
from libvirt import libvirtError
import json
import socket
@ -62,3 +65,24 @@ def get_client_ip(request):
def get_hostname_by_ip(ip):
addrs = socket.gethostbyaddr(ip)
return addrs[0]
def get_vdi_url(request, vname):
instance = Instance.objects.get(name=vname)
compute = instance.compute
data = {}
try:
conn = wvmInstance(compute.hostname,
compute.login,
compute.password,
compute.type,
instance.name)
fqdn = get_hostname_by_ip(compute.hostname)
url = "{}://{}:{}".format(conn.get_console_type(), fqdn, conn.get_console_port())
response = url
return HttpResponse(response)
except libvirtError as lib_err:
err = "Error getting vdi url for {}".format(vname)
raise Http404(err)