2022-12-11 06:49:10 +00:00
|
|
|
import {requestTicket, setTicket, request} from "./utils.js";
|
|
|
|
|
2022-12-11 02:02:29 +00:00
|
|
|
window.addEventListener("DOMContentLoaded", init);
|
|
|
|
|
|
|
|
async function init () {
|
|
|
|
let cookie = document.cookie;
|
2022-12-11 06:49:10 +00:00
|
|
|
if (cookie === '') {
|
2022-12-12 22:57:43 +00:00
|
|
|
window.location.href = "login.html";
|
2022-12-11 02:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let nodes = await request("/nodes", "GET", null);
|
2022-12-14 21:37:30 +00:00
|
|
|
let instances = [];
|
2022-12-11 23:24:19 +00:00
|
|
|
|
2022-12-14 21:37:30 +00:00
|
|
|
let instanceContainer = document.getElementById("instance-container")
|
|
|
|
|
2022-12-14 21:47:28 +00:00
|
|
|
for (let i = 0; i < nodes.data.length; i++) {
|
|
|
|
let nodeName = nodes.data[i].node;
|
|
|
|
let nodeStatus = nodes.data[i].status;
|
|
|
|
|
|
|
|
let qemu = await request(`/nodes/${nodeName}/qemu`, "GET");
|
2022-12-15 01:01:38 +00:00
|
|
|
qemu.data.forEach((item) => {
|
|
|
|
item.node = {name: nodeName, status: nodeStatus};
|
|
|
|
item.type = "qemu";
|
|
|
|
});
|
2022-12-14 21:47:28 +00:00
|
|
|
let lxc = await request(`/nodes/${nodeName}/lxc`, "GET");
|
2022-12-15 01:01:38 +00:00
|
|
|
lxc.data.forEach((item) => {
|
|
|
|
item.node = {name: nodeName, status: nodeStatus};
|
|
|
|
item.type = "lxc";
|
|
|
|
});
|
2022-12-14 21:40:19 +00:00
|
|
|
instances = instances.concat(qemu.data, lxc.data);
|
2022-12-14 21:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
instances.sort((a, b) => (a.vmid > b.vmid) ? 1 : -1);
|
2022-12-11 23:06:10 +00:00
|
|
|
|
2022-12-14 21:37:30 +00:00
|
|
|
for(let i = 0; i < instances.length; i++) {
|
|
|
|
let newInstance = document.createElement("instance-article");
|
|
|
|
newInstance.data = instances[i];
|
|
|
|
instanceContainer.append(newInstance);
|
2022-12-11 02:02:29 +00:00
|
|
|
}
|
|
|
|
}
|