mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 15:45:23 +00:00
get host info from compute not instance
This commit is contained in:
parent
e72073fa79
commit
966da065b4
3 changed files with 9 additions and 11 deletions
|
@ -8,6 +8,5 @@ urlpatterns = [
|
||||||
views.os_metadata_json, name='ds_openstack_metadata'),
|
views.os_metadata_json, name='ds_openstack_metadata'),
|
||||||
url(r'^openstack/(?P<version>[\w\-\.]+)/user_data$',
|
url(r'^openstack/(?P<version>[\w\-\.]+)/user_data$',
|
||||||
views.os_userdata, name='ds_openstack_userdata'),
|
views.os_userdata, name='ds_openstack_userdata'),
|
||||||
url(r'^vdi/(?P<vname>[\w\-\.]+)/$',
|
url(r'^vdi/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$', views.get_vdi_url, name='vdi_url'),
|
||||||
views.get_vdi_url, name='vdi_url'),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.http import HttpResponse, Http404
|
from django.http import HttpResponse, Http404
|
||||||
from libvirt import libvirtError
|
from libvirt import libvirtError
|
||||||
from accounts.models import UserInstance, UserSSHKey
|
from accounts.models import UserInstance, UserSSHKey
|
||||||
from instances.models import Instance
|
from computes.models import Compute
|
||||||
from vrtManager.instance import wvmInstance
|
from vrtManager.instance import wvmInstance
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,26 +88,25 @@ def get_hostname_by_ip(ip):
|
||||||
return addrs[0]
|
return addrs[0]
|
||||||
|
|
||||||
|
|
||||||
def get_vdi_url(request, vname):
|
def get_vdi_url(request, compute_id, vname):
|
||||||
"""
|
"""
|
||||||
:param request:
|
:param request:
|
||||||
:param vname:
|
:param vname:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
instance = Instance.objects.get(name=vname)
|
compute = get_object_or_404(Compute, pk=compute_id)
|
||||||
compute = instance.compute
|
|
||||||
data = {}
|
data = {}
|
||||||
try:
|
try:
|
||||||
conn = wvmInstance(compute.hostname,
|
conn = wvmInstance(compute.hostname,
|
||||||
compute.login,
|
compute.login,
|
||||||
compute.password,
|
compute.password,
|
||||||
compute.type,
|
compute.type,
|
||||||
instance.name)
|
vname)
|
||||||
|
|
||||||
fqdn = get_hostname_by_ip(compute.hostname)
|
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
|
response = url
|
||||||
return HttpResponse(response)
|
return HttpResponse(response)
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
err = "Error getting vdi url for {}".format(vname)
|
err = f"Error getting vdi url for {vname}"
|
||||||
raise Http404(err)
|
raise Http404(err)
|
||||||
|
|
|
@ -1817,7 +1817,7 @@
|
||||||
});
|
});
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// set vdi url
|
// 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_input").attr("value", data);
|
||||||
$("#vdi_url").attr("href", data);
|
$("#vdi_url").attr("href", data);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue