1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00
webvirtcloud/static/js/vm_addresses.js
catborise aab8dbf1df perf(instances): a VM page does not wait for the guest agent's addresses
A running VM's page read its addresses while it rendered: the guest agent,
when its channel is connected but it does not answer, holds the page (and
a gunicorn worker) for its whole 10 s timeout, on every load. The page now
shows them once it has loaded: vm_addresses.js asks the new
instances/<pk>/addresses/ for each NIC's addresses and fills the header's
IPv4 and each network card's IPv4 and IPv6.
2026-11-07 15:42:49 +03:00

20 lines
993 B
JavaScript

// The VM's addresses come once the page has loaded: the guest agent may take
// its whole timeout (instances.views.nic_addresses). An element with
// data-address-family shows those of the NICs in data-address-mac (MACs
// separated by spaces: not the guest's own bridges); data-empty when there
// are none.
(function () {
const places = document.querySelectorAll("[data-address-family]");
const show = (found) => {
for (const place of places) {
const nics = place.dataset.addressMac.split(" ").filter(Boolean).map((mac) => found[mac] || {});
const addresses = nics.flatMap((nic) => nic[place.dataset.addressFamily] || []);
place.textContent = addresses.join(", ") || place.dataset.empty;
place.classList.toggle("text-body-secondary", !addresses.length);
}
};
fetch(document.currentScript.dataset.url, {headers: {Accept: "application/json"}})
.then((response) => (response.ok ? response.json() : {}))
.catch(() => ({}))
.then(show);
})();