From d5cc696d73d7999fb4b5563e35fc6234d73312f7 Mon Sep 17 00:00:00 2001 From: catborise Date: Wed, 25 Nov 2026 11:44:35 +0300 Subject: [PATCH] feat(instances): the VM page shows the VM's screen A running or paused VM with a VNC or SPICE console shows its screen beside the summary (virDomainScreenshot, PNG), read again every 10 s while the page is in view; clicking it opens the console. It is for those who may open the console (the screen shows what the console does) and is left out while there is none to show, also on a host whose libvirt gives PPM. The VM list does not read screens: one a VM would cost too much. --- console/views.py | 9 +-- doc/behavior-changes.md | 1 + instances/templates/instance.html | 18 ++++- instances/tests/test_pending_edits.py | 16 +++++ instances/tests/test_screen.py | 66 ++++++++++++++++++ instances/urls.py | 1 + instances/utils.py | 11 ++- instances/views.py | 28 ++++++++ locale/tr/LC_MESSAGES/django.mo | Bin 274023 -> 274075 bytes locale/tr/LC_MESSAGES/django.po | 4 ++ locale/uk/LC_MESSAGES/django.mo | Bin 350157 -> 350217 bytes locale/uk/LC_MESSAGES/django.po | 4 ++ locale/zh/LC_MESSAGES/django.mo | Bin 255653 -> 255707 bytes locale/zh/LC_MESSAGES/django.po | 4 ++ static/css/webvirtcloud.css | 17 +++++ static/js/instance_page.js | 19 +++++ vrtManager/instance.py | 15 ++++ .../tests/test_authorization_matrix.py | 1 + 18 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 instances/tests/test_screen.py diff --git a/console/views.py b/console/views.py index 656e9238..6f5d618f 100644 --- a/console/views.py +++ b/console/views.py @@ -11,12 +11,10 @@ from django.conf import settings from django.shortcuts import redirect, render from django.utils.translation import gettext_lazy as _ from instances.models import Instance -from instances.utils import can_open_console +from instances.utils import can_open_console, novnc_unreachable from libvirt import libvirtError from operations.utils import safe_text -from vrtManager.connection import CONN_TCP, CONN_TLS from vrtManager.instance import wvmInstance -from vrtManager.util import is_loopback from webvirtcloud.middleware import error_text logger = logging.getLogger(__name__) @@ -68,9 +66,8 @@ def console(request, compute_id, uuid): running = conn.instance.isActive() # novncd reaches a console that listens on its host's loopback only # through SSH (or on this host); the running VM's listener, as novncd sees it - unreachable = instance.compute.type in (CONN_TCP, CONN_TLS) and bool( - conn.get_console_socket() or is_loopback(conn.get_console_listener_addr()) - ) + unreachable = novnc_unreachable(instance.compute.type, conn.get_console_socket(), + conn.get_console_listener_addr()) except libvirtError as err: # the host or the VM could not be read: the page says that, not to check the console settings logger.warning("Console of %s on %s: %s", instance.name, instance.compute.name, safe_text(err)) diff --git a/doc/behavior-changes.md b/doc/behavior-changes.md index fab22611..cf04588e 100644 --- a/doc/behavior-changes.md +++ b/doc/behavior-changes.md @@ -33,6 +33,7 @@ What an update from an older version changes for operators and users. To run the - On a running VM the edit forms show the settings as they will be at the next start, so saving an edit no longer reverts another pending change. - External snapshots need libvirt 9.9 or newer on the computes. libvirt 9.10 (openEuler 24.03 LTS) refuses to revert a snapshot taken without memory of a running or paused VM ("Invalid target domain state 'disk-snapshot'"); 11.10 reverts it. A VM's snapshots form one chain: after a revert, delete the newer snapshots before taking another. An internal snapshot is reverted only on a shut-off VM. Snapshot names no longer get an `s1.` prefix. A snapshot an older version took of a UEFI VM can only be deleted, not reverted. On NFS, the qemu user needs write access to the image directory to remove merged snapshot files. - A superuser limits a disk's I/O (IOPS and MiB/s, reads and writes together) under its Device details on the Disks tab; a running VM gets the limit at once. +- The VM page shows a running or paused VM's screen beside its summary, read again every 10 seconds, to those who may open its console; clicking it opens the console. It needs a VNC or SPICE console and a host whose libvirt gives screenshots as PNG (libvirt 9 and QEMU 7.1 or later); otherwise it is not shown. - **Free unused space** on a running VM's Disks tab (superusers) has its guest agent trim each file system (`guest-fstrim`, a job that lists what each one trimmed). Only a disk with the discard mode `unmap` (Device details, from the VM's next start; Settings > Disk Discard for new disks) passes it to its image file, which then shrinks; the tab says when no disk has it. - A storage volume a VM still needs (a disk, a backing file or a snapshot's file) is not deleted; deleting a VM with its files keeps a file another compute's VM or volume uses at the same path, and is refused before the VM is stopped when one of the other computes cannot be reached. A pool's page names the VMs of its host that use each volume and lists those the host does not use. - A VM that vanishes from its compute, or whose compute is deleted, keeps its owners, tags, protection and schedules for `INSTANCE_OWNERSHIP_RETENTION_DAYS` (30) in case the same UUID comes back, and its backups are linked to it again; superusers manage these records on the "Removed VMs" page. diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 6791b693..322174ad 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -21,7 +21,8 @@ data-opens-on="{% if instance.is_template and can_clone %}#clone{% endif %}" data-random-mac-url="{% url 'instances:random_mac_address' %}" {% if can_open_console and vdi_reachable %}data-vdi-url="{% url 'vdi_url' compute.id instance.name %}"{% endif %}> -
+
+
@@ -88,6 +89,21 @@
{% endif %} +
+ {% if show_screen %} + {# the VM's screen, read by instance_page.js every few seconds and shown once one has come; opens the console where it can #} + {% if screen_opens_console %} + + {% else %} + + {% endif %} + {% endif %}