1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00
webvirtcloud/static/js/instance_status.js
catborise a2f4d3fe06 fix(instances): an open VM page follows its VM's removal on the host
A VM undefined outside the panel (virsh, virt-manager) while its page was
open made the state and statistics polls answer 500 every 5 seconds, each
an error in the panel's log, and the page stayed as it was. A page read of
an object the host no longer has is now 404, and the VM page reloads on a
404 of its state: it then goes to the VM list with "no longer on its host",
or shows that the VM is not found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
2026-11-10 13:19:39 +03:00

30 lines
1.2 KiB
JavaScript

// The VM page reloads when the VM's state changes (instance.html, #vm-summary),
// or when the VM is gone: the page then says so.
backgroundJobRunning = false;
// not "status": that is window.status, which the browser may not keep
var vm_summary = document.getElementById("vm-summary");
var vm_status = Number(vm_summary.dataset.status);
var host_lost = document.getElementById("vm-host-lost");
function reloadWhenFree() {
// the page in use (a dialog open, a field in use, an XML edit not saved): the reload waits (poll.js)
if (!backgroundJobRunning && !pageInUse()) {
window.location.reload();
}
}
var status_poll = pollWhileVisible(5000, function () {
return $.getJSON(vm_summary.dataset.statusUrl).fail(function (xhr) {
// a failed read (a host that does not answer, a session that ended, the VM gone while
// the page is in use) leaves the page as it was: it says so until a read is answered
host_lost.hidden = false;
if (xhr.status == 404) {
reloadWhenFree();
}
});
}, function get_status(data) {
host_lost.hidden = true;
if (data['status'] != vm_status) {
reloadWhenFree();
}
});