mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-23 22:55:23 +00:00
add vdiconsole datasource endpoint. provides vdi url for remote-viewer.
add instance/access/vdi panel
This commit is contained in:
parent
27a7a7a365
commit
464e7bee39
3 changed files with 46 additions and 0 deletions
|
@ -8,4 +8,6 @@ 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'),
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -241,6 +241,13 @@
|
|||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% ifequal status 1 %}
|
||||
<li role="presentation">
|
||||
<a href="#vdiconsole" aria-controls="vdiconsole" role="tab" data-toggle="tab">
|
||||
{% trans "VDI" %}
|
||||
</a>
|
||||
</li>
|
||||
{% endifequal %}
|
||||
</ul>
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
|
@ -297,6 +304,13 @@
|
|||
<div class="clearfix"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% ifequal status 1 %}
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="vdiconsole">
|
||||
<p>{% trans "This action opens a remote viewer with a connection to the console of the instance." %}</p>
|
||||
<a href="#" class="btn btn-lg btn-success pull-right" id="vdi_url" >{% trans "VDI" %}</a>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
{% endifequal %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1305,6 +1319,12 @@
|
|||
$("#console_select_listen_address option[value='" + console_listen_address + "']").prop('selected', true);
|
||||
}
|
||||
});
|
||||
$(document).ready(function () {
|
||||
// set vdi url
|
||||
$.get("/datasource/vdi/{{ vname }}/", function(data) {
|
||||
$("#vdi_url").attr("href", data);
|
||||
});
|
||||
});
|
||||
{% if not request.user.is_superuser %}
|
||||
$('#select_clone_name').on('change', function () {
|
||||
update_clone_disk_name($(this).val());
|
||||
|
|
Loading…
Reference in a new issue