From db3437894d513f551e5118a23c6393a26418f9ec Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 16 Apr 2024 21:38:25 +0000 Subject: [PATCH] update for new pool and node format --- account.html | 2 +- scripts/account.js | 12 +++++------ scripts/config.js | 29 ++++++------------------- scripts/index.js | 53 +++++++++++++++++++++++----------------------- 4 files changed, 39 insertions(+), 57 deletions(-) diff --git a/account.html b/account.html index 4a2f349..a259d78 100644 --- a/account.html +++ b/account.html @@ -59,7 +59,7 @@

Account Details

Username:

-

Pool:

+

Pools:

VMID Range:

Nodes:

diff --git a/scripts/account.js b/scripts/account.js index 87df0e4..3871e5e 100644 --- a/scripts/account.js +++ b/scripts/account.js @@ -29,18 +29,16 @@ async function init () { let resources = requestAPI("/user/dynamic/resources"); let meta = requestAPI("/global/config/resources"); - let instances = requestAPI("/user/config/cluster"); - let nodes = requestAPI("/user/config/nodes"); + let userCluster = requestAPI("/user/config/cluster"); resources = await resources; meta = await meta; - instances = await instances; - nodes = await nodes; + userCluster = await userCluster; document.querySelector("#username").innerText = `Username: ${getCookie("username")}`; - document.querySelector("#pool").innerText = `Pool: ${instances.pool}`; - document.querySelector("#vmid").innerText = `VMID Range: ${instances.vmid.min} - ${instances.vmid.max}`; - document.querySelector("#nodes").innerText = `Nodes: ${nodes.toString()}`; + document.querySelector("#pool").innerText = `Pools: ${Object.keys(userCluster.pools).toString()}`; + document.querySelector("#vmid").innerText = `VMID Range: ${userCluster.vmid.min} - ${userCluster.vmid.max}`; + document.querySelector("#nodes").innerText = `Nodes: ${Object.keys(userCluster.nodes).toString()}`; populateResources("#resource-container", meta, resources); diff --git a/scripts/config.js b/scripts/config.js index 1caed75..f089ff5 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -409,23 +409,13 @@ async function handleDiskAdd () { } async function handleCDAdd () { - const content = "iso"; - const storage = await requestPVE(`/nodes/${node}/storage`, "GET"); + const isos = await requestAPI("/user/vm-isos", "GET"); const header = "Add a CDROM"; - let storageOptions = ""; - storage.data.forEach((element) => { - if (element.content.includes(content)) { - storageOptions += `"`; - } - }); - const storageSelect = ``; - const body = `
- ${storageSelect}
`; @@ -446,17 +436,12 @@ async function handleCDAdd () { } }); - d.querySelector("#storage-select").addEventListener("change", async () => { - const storage = document.querySelector("#storage-select").value; - const ISOSelect = document.querySelector("#iso-select"); - ISOSelect.innerHTML = ""; - const isos = await requestPVE(`/nodes/${node}/storage/${storage}/content`, "GET", { content }); - isos.data.forEach((element) => { - if (element.content.includes(content)) { - ISOSelect.append(new Option(element.volid.replace(`${storage}:${content}/`, ""), element.volid)); - } - }); - }); + const isoSelect = d.querySelector("#iso-select"); + + for (const iso of isos) { + isoSelect.append(new Option(iso.name, iso.volid)) + } + isoSelect.selectedIndex = -1; } async function populateNetworks () { diff --git a/scripts/index.js b/scripts/index.js index b63214a..99c397d 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -90,6 +90,8 @@ async function handleInstanceAdd () { + + @@ -97,8 +99,6 @@ async function handleInstanceAdd () {

Container Options

- - @@ -110,12 +110,15 @@ async function handleInstanceAdd () { `; + const templates = await requestAPI("/user/ct-templates", "GET"); + const d = dialog(header, body, async (result, form) => { if (result === "confirm") { const body = { name: form.get("name"), cores: form.get("cores"), - memory: form.get("memory") + memory: form.get("memory"), + pool: form.get("pool") }; if (form.get("type") === "lxc") { body.swap = form.get("swap"); @@ -155,10 +158,6 @@ async function handleInstanceAdd () { } }); - const templateContent = "iso"; - const templateStorage = d.querySelector("#template-storage"); - templateStorage.selectedIndex = -1; - const rootfsContent = "rootdir"; const rootfsStorage = d.querySelector("#rootfs-storage"); rootfsStorage.selectedIndex = -1; @@ -168,27 +167,24 @@ async function handleInstanceAdd () { const nodeSelect = d.querySelector("#node"); const clusterNodes = await requestPVE("/nodes", "GET"); - const allowedNodes = await requestAPI("/user/config/nodes", "GET"); + const allowedNodes = Object.keys(userCluster.nodes) clusterNodes.data.forEach((element) => { if (element.status === "online" && allowedNodes.includes(element.node)) { nodeSelect.add(new Option(element.node)); } }); nodeSelect.selectedIndex = -1; - nodeSelect.addEventListener("change", async () => { // change template and rootfs storage based on node + nodeSelect.addEventListener("change", async () => { // change rootfs storage based on node const node = nodeSelect.value; const storage = await requestPVE(`/nodes/${node}/storage`, "GET"); storage.data.forEach((element) => { - if (element.content.includes(templateContent)) { - templateStorage.add(new Option(element.storage)); - } if (element.content.includes(rootfsContent)) { rootfsStorage.add(new Option(element.storage)); } }); - templateStorage.selectedIndex = -1; rootfsStorage.selectedIndex = -1; + // set core and memory min/max depending on node selected if (node in userResources.cores.nodes) { d.querySelector("#cores").max = userResources.cores.nodes[node].avail; } @@ -202,21 +198,24 @@ async function handleInstanceAdd () { else { d.querySelector("#memory").max = userResources.memory.global.avail; } - - d.querySelector("#vmid").min = userCluster.vmid.min; - d.querySelector("#vmid").max = userCluster.vmid.max; }); + // set vmid min/max + d.querySelector("#vmid").min = userCluster.vmid.min; + d.querySelector("#vmid").max = userCluster.vmid.max; + + // add user pools to selector + const poolSelect = d.querySelector("#pool"); + const userPools = Object.keys(userCluster.pools); + userPools.forEach((element) => { + poolSelect.add(new Option(element)); + }); + poolSelect.selectedIndex = -1; + + // add template images to selector const templateImage = d.querySelector("#template-image"); // populate templateImage depending on selected image storage - templateStorage.addEventListener("change", async () => { - templateImage.innerHTML = ""; - const content = "vztmpl"; - const images = await requestPVE(`/nodes/${nodeSelect.value}/storage/${templateStorage.value}/content`, "GET"); - images.data.forEach((element) => { - if (element.content.includes(content)) { - templateImage.append(new Option(element.volid.replace(`${templateStorage.value}:${content}/`, ""), element.volid)); - } - }); - templateImage.selectedIndex = -1; - }); + for (const template of templates) { + templateImage.append(new Option(template.name, template.volid)) + } + templateImage.selectedIndex = -1; }