diff --git a/datasource/urls.py b/datasource/urls.py index 9183d41..ec02ad3 100644 --- a/datasource/urls.py +++ b/datasource/urls.py @@ -8,4 +8,6 @@ urlpatterns = [ views.os_metadata_json, name='ds_openstack_metadata'), url(r'^openstack/(?P[\w\-\.]+)/user_data$', views.os_userdata, name='ds_openstack_userdata'), + url(r'^vdi/(?P[\w\-\.]+)/$', + views.get_vdi_url, name='vdi_url'), ] diff --git a/datasource/views.py b/datasource/views.py index 9264717..d23d99a 100644 --- a/datasource/views.py +++ b/datasource/views.py @@ -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) + diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 061c394..13336b5 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -241,6 +241,13 @@ {% endif %} + {% ifequal status 1 %} +
  • + + {% trans "VDI" %} + +
  • + {% endifequal %}
    @@ -297,6 +304,13 @@
    {% endif %} + {% ifequal status 1 %} +
    +

    {% trans "This action opens a remote viewer with a connection to the console of the instance." %}

    + {% trans "VDI" %} +
    +
    + {% endifequal %} @@ -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());