diff --git a/README.md b/README.md index 3fb4e6e..4bd26fb 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ print(''.join([random.SystemRandom().choice(haystack) for _ in range(50)])) ### Install WebVirtCloud panel (Ubuntu) ```bash -sudo apt-get -y install git python-virtualenv python-dev python-lxml libvirt-dev zlib1g-dev nginx supervisor libsasl2-modules gcc pkg-config python-guestfs +sudo apt-get -y install git python-virtualenv python-dev python-lxml libvirt-dev zlib1g-dev libxslt1-dev nginx supervisor libsasl2-modules gcc pkg-config python-guestfs git clone https://github.com/retspen/webvirtcloud cd webvirtcloud cp webvirtcloud/settings.py.template webvirtcloud/settings.py diff --git a/accounts/views.py b/accounts/views.py index 0ef1f02..494bdd6 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -56,6 +56,9 @@ def profile(request): if keypublic == key.keypublic: msg = _("Public key already exist") error_messages.append(msg) + if '\n' in keypublic or '\r' in keypublic: + msg = _("Invalid characters in public key") + error_messages.append(msg) if not error_messages: addkeypublic = UserSSHKey(user_id=request.user.id, keyname=keyname, keypublic=keypublic) addkeypublic.save() diff --git a/conf/requirements.txt b/conf/requirements.txt index c47d4dc..49903c0 100644 --- a/conf/requirements.txt +++ b/conf/requirements.txt @@ -2,4 +2,6 @@ Django==1.11.14 websockify==0.8.0 gunicorn==19.9.0 lxml==4.2.3 -libvirt-python==4.4.0 \ No newline at end of file +libvirt-python==4.4.0 +pytz + 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 2d27f18..04e67da 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -36,7 +36,7 @@ {% endfor %} on - {{ compute.name}} - {{ compute.hostname }} + {{ compute.name }}{% if compute.name != compute.hostname %} - {{ compute.hostname }}{% endif %} {% if user_quota_msg %} @@ -243,6 +243,13 @@ {% endif %} + {% ifequal status 1 %} +
  • + + {% trans "VDI" %} + +
  • + {% endifequal %}
    @@ -311,6 +318,13 @@
    {% endif %} + {% ifequal status 1 %} +
    +

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

    + {% trans "VDI" %} +
    +
    + {% endifequal %} @@ -860,6 +874,10 @@ + {% elif clone_instance_auto_name %} +
    + +
    {% else %}
    +
    {% ifequal status 5 %} @@ -1210,7 +1228,7 @@ }