ProxmoxAAS-Dashboard/scripts/index.js

42 lines
1.2 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 () {
let cookie = document.cookie;
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");
qemu.data.forEach((item) => {
2022-12-14 21:48:29 +00:00
item.node = {};
2022-12-14 21:47:28 +00:00
item.node.name = nodeName;
item.node.status = nodeStatus;
});
let lxc = await request(`/nodes/${nodeName}/lxc`, "GET");
lxc.data.forEach((item) => {
2022-12-14 21:48:29 +00:00
item.node = {};
2022-12-14 21:47:28 +00:00
item.node.name = nodeName;
item.node.status = nodeStatus;
});
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
}
}