1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +00:00

get host info from compute not instance

This commit is contained in:
catborise 2020-05-14 16:45:37 +03:00 committed by catborise
parent e72073fa79
commit 966da065b4
3 changed files with 9 additions and 11 deletions

View file

@ -8,6 +8,5 @@ urlpatterns = [
views.os_metadata_json, name='ds_openstack_metadata'),
url(r'^openstack/(?P<version>[\w\-\.]+)/user_data$',
views.os_userdata, name='ds_openstack_userdata'),
url(r'^vdi/(?P<vname>[\w\-\.]+)/$',
views.get_vdi_url, name='vdi_url'),
url(r'^vdi/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$', views.get_vdi_url, name='vdi_url'),
]

View file

@ -1,10 +1,10 @@
import json
import socket
from django.shortcuts import render
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse, Http404
from libvirt import libvirtError
from accounts.models import UserInstance, UserSSHKey
from instances.models import Instance
from computes.models import Compute
from vrtManager.instance import wvmInstance
@ -88,26 +88,25 @@ def get_hostname_by_ip(ip):
return addrs[0]
def get_vdi_url(request, vname):
def get_vdi_url(request, compute_id, vname):
"""
:param request:
:param vname:
:return:
"""
instance = Instance.objects.get(name=vname)
compute = instance.compute
compute = get_object_or_404(Compute, pk=compute_id)
data = {}
try:
conn = wvmInstance(compute.hostname,
compute.login,
compute.password,
compute.type,
instance.name)
vname)
fqdn = get_hostname_by_ip(compute.hostname)
url = "{}://{}:{}".format(conn.get_console_type(), fqdn, conn.get_console_port())
url = f"{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)
err = f"Error getting vdi url for {vname}"
raise Http404(err)

View file

@ -1817,7 +1817,7 @@
});
$(document).ready(function () {
// set vdi url
$.get("{% url 'vdi_url' vname %}", function(data) {
$.get("{% url 'vdi_url' compute_id vname %}", function(data) {
$("#vdi_url_input").attr("value", data);
$("#vdi_url").attr("href", data);
});