From cb5b0c1ecb9377ecaab25be750aeccecb3899ecf Mon Sep 17 00:00:00 2001 From: catborise Date: Tue, 4 Sep 2018 15:28:51 +0300 Subject: [PATCH 1/2] add title to snapshot operations and fix redirect path --- instances/templates/instance.html | 6 +++--- instances/views.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 98cf692..3c650ff 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -512,7 +512,7 @@
  • - {% trans "Manage Snapshot" %} + {% trans "Manage Snapshots" %}
  • @@ -560,7 +560,7 @@
    {% csrf_token %} {% ifequal status 5 %} - {% else %} @@ -573,7 +573,7 @@ {% csrf_token %} -
    diff --git a/instances/views.py b/instances/views.py index ac188ed..5bf95b1 100644 --- a/instances/views.py +++ b/instances/views.py @@ -565,14 +565,14 @@ def instance(request, compute_id, vname): conn.create_snapshot(name) msg = _("New snapshot") addlogmsg(request.user.username, instance.name, msg) - return HttpResponseRedirect(request.get_full_path() + '#restoresnapshot') + return HttpResponseRedirect(request.get_full_path() + '#managesnapshot') if 'delete_snapshot' in request.POST: snap_name = request.POST.get('name', '') conn.snapshot_delete(snap_name) msg = _("Delete snapshot") addlogmsg(request.user.username, instance.name, msg) - return HttpResponseRedirect(request.get_full_path() + '#restoresnapshot') + return HttpResponseRedirect(request.get_full_path() + '#managesnapshot') if 'revert_snapshot' in request.POST: snap_name = request.POST.get('name', '') From 0f7a110535554f0a92e4d780c31a5e448efbd542 Mon Sep 17 00:00:00 2001 From: catborise Date: Wed, 5 Sep 2018 09:30:08 +0300 Subject: [PATCH 2/2] show vdi url on access tab. some typo and convention fix. gethostbyaddr exception mitigated. --- datasource/views.py | 17 +++++++++++++---- instances/templates/instance.html | 8 +++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/datasource/views.py b/datasource/views.py index d23d99a..163ecb5 100644 --- a/datasource/views.py +++ b/datasource/views.py @@ -7,13 +7,15 @@ from libvirt import libvirtError import json import socket -OS_VERSIONS = [ 'latest', '' ] +OS_VERSIONS = ['latest', ''] OS_UUID = "iid-dswebvirtcloud" + def os_index(request): response = '\n'.join(OS_VERSIONS) return HttpResponse(response) + def os_metadata_json(request, version): """ :param request: @@ -27,9 +29,10 @@ def os_metadata_json(request, version): response = { 'uuid': OS_UUID, 'hostname': hostname } return HttpResponse(json.dumps(response)) else: - err = 'Invalid version: %s' % version + err = 'Invalid version: {}'.format(version) raise Http404(err) + def os_userdata(request, version): """ :param request: @@ -51,9 +54,10 @@ def os_userdata(request, version): return render(request, 'user_data', locals()) else: - err = 'Invalid version: %s' % version + err = 'Invalid version: {}'.format(version) raise Http404(err) + def get_client_ip(request): x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: @@ -62,10 +66,15 @@ def get_client_ip(request): ip = request.META.get('REMOTE_ADDR') return ip + def get_hostname_by_ip(ip): - addrs = socket.gethostbyaddr(ip) + try: + addrs = socket.gethostbyaddr(ip) + except Exception: + addrs = [ip,] return addrs[0] + def get_vdi_url(request, vname): instance = Instance.objects.get(name=vname) compute = instance.compute diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 3c650ff..ba5c891 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -321,7 +321,12 @@ {% ifequal status 1 %}

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

    - {% trans "VDI" %} +
    + + + {% trans "VDI" %} + +
    {% endifequal %} @@ -1337,6 +1342,7 @@ $(document).ready(function () { // set vdi url $.get("/datasource/vdi/{{ vname }}/", function(data) { + $("#vdi_url_input").attr("value", data); $("#vdi_url").attr("href", data); }); });