2023-01-09 23:08:45 +00:00
|
|
|
import {request, goToPage, deleteAllCookies} from "./utils.js";
|
2022-12-11 06:49:10 +00:00
|
|
|
|
2022-12-11 02:02:29 +00:00
|
|
|
window.addEventListener("DOMContentLoaded", init);
|
|
|
|
|
|
|
|
async function init () {
|
2022-12-18 00:07:18 +00:00
|
|
|
await populateInstances();
|
2023-01-09 23:08:45 +00:00
|
|
|
|
|
|
|
let instances = document.querySelector("nav #instances");
|
|
|
|
instances.addEventListener("click", () => {
|
|
|
|
goToPage("index.html");
|
|
|
|
});
|
|
|
|
|
|
|
|
let logout = document.querySelector("nav #logout");
|
|
|
|
logout.addEventListener("click", () => {
|
|
|
|
deleteAllCookies();
|
|
|
|
goToPage("login.html");
|
|
|
|
});
|
2022-12-18 00:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function populateInstances () {
|
2022-12-11 02:02:29 +00:00
|
|
|
let cookie = document.cookie;
|
2022-12-18 00:07:18 +00:00
|
|
|
if (cookie === "") {
|
2022-12-19 05:58:46 +00:00
|
|
|
goToPage("login.html");
|
2022-12-11 02:02:29 +00:00
|
|
|
}
|
|
|
|
|
2023-01-17 20:24:51 +00:00
|
|
|
let resources = await request("/cluster/resources", "GET", null);
|
2022-12-11 23:24:19 +00:00
|
|
|
|
2022-12-14 21:37:30 +00:00
|
|
|
let instanceContainer = document.getElementById("instance-container")
|
|
|
|
|
2023-01-17 20:26:19 +00:00
|
|
|
let instances = [];
|
2023-01-17 20:24:51 +00:00
|
|
|
|
|
|
|
resources.data.forEach((element) => {
|
|
|
|
if (element.type === "lxc" || element.type === "qemu") {
|
|
|
|
let nodeName = element.node;
|
|
|
|
let nodeStatus = resources.find(iem => item.node === nodeName).status;
|
|
|
|
element.node = {name: nodeName, status: nodeStatus};
|
2023-01-17 20:26:19 +00:00
|
|
|
instances.push(element);
|
2023-01-17 20:24:51 +00:00
|
|
|
}
|
|
|
|
});
|
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-18 00:07:18 +00:00
|
|
|
instanceContainer.innerText = "";
|
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
|
|
|
}
|
|
|
|
}
|