ProxmoxAAS-Dashboard/scripts/index.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

import {requestTicket, setTicket, request} from "./utils.js";
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();
2022-12-18 00:15:28 +00:00
//setInterval(populateInstances, 1000);
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-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};
2022-12-15 01:31:05 +00:00
item.maxswap = 0;
2022-12-15 01:01:38 +00:00
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-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
}
}