mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +00:00
libvirt gives each state its reason; the panel showed only the state, so a VM QEMU paused because its storage filled up read "Suspended" like one an administrator paused. - instances.states.REASONS: the fault reasons told (disk error, watchdog, guest crash or kernel panic, a crash of the guest or its QEMU process, libvirt stopping it after a restart, failed post-copy migration, libvirt error, failed start); the ordinary ones (user, migration, snapshot) are not - the lists read the reason with the state in their one getAllDomainStats call (get_domain_rows, get_domain_states: a change of reason reloads a list) and show it under the state badge - the VM page reads state and reason in one virDomainGetState (a reason means something only with its own state) and tells it in an alert; a VM paused by a disk error names each disk and what it met (virDomainGetDiskErrors), and when a storage has no free space, what to do: an administrator frees space and resumes it. Disk errors are read only then: libvirt keeps the last one after a resume. The page's poll reloads on a change of reason too Checked live on a Vagrant host: a guest filling a disk on a 40 MiB pool was paused (I/O error, vda: no space); the page said so, and after the pool grew and the VM was resumed the alert was gone.
32 lines
1.4 KiB
JavaScript
32 lines
1.4 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);
|
|
// why it is in its state (libvirt's reason): a VM paused by hand that pauses again on a disk error stays paused
|
|
var vm_reason = vm_summary.dataset.reason;
|
|
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 || String(data['reason']) !== vm_reason) {
|
|
reloadWhenFree();
|
|
}
|
|
});
|