From 54533e213b519abdc2efa2b837296360f44d7b40 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 12 May 2023 21:14:49 +0000 Subject: [PATCH] add node vmid cores and memory limits to inputs in instance create form Signed-off-by: Arthur Lu --- scripts/account.js | 8 ++++---- scripts/index.js | 14 +++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/account.js b/scripts/account.js index 7a14fa7..2fa5922 100644 --- a/scripts/account.js +++ b/scripts/account.js @@ -15,13 +15,13 @@ async function init () { if (cookie === "") { goToPage("login.html"); } - let user = await requestAPI("/user"); - let resources = user.resources; - let instances = user.instances; + let resources = await requestAPI("/user/resources"); + let instances = await requestAPI("/user/instances"); + let nodes = await requestAPI("/user/nodes"); 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: ${user.nodes.toString()}`; + document.querySelector("#nodes").innerText = `Nodes: ${nodes.toString()}`; buildResourceTable(resources, "#resource-table"); } diff --git a/scripts/index.js b/scripts/index.js index fd49e26..85b8238 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -125,6 +125,13 @@ async function handleInstanceAdd () { } }); + let userResources = await requestAPI("/user/resources", "GET"); + let userInstances = await requestAPI("/user/instances", "GET") + d.querySelector("#cores").max = userResources.avail.cores; + d.querySelector("#memory").max = userResources.avail.memory; + d.querySelector("#vmid").min = userInstances.vmid.min; + d.querySelector("#vmid").max = userInstances.vmid.max; + let typeSelect = d.querySelector("#type"); typeSelect.selectedIndex = -1; typeSelect.addEventListener("change", () => { @@ -151,9 +158,10 @@ async function handleInstanceAdd () { rootfsStorage.selectedIndex = -1; let nodeSelect = d.querySelector("#node"); - let nodes = await requestPVE("/nodes", "GET"); - nodes.data.forEach((element) => { - if (element.status === "online") { + let clusterNodes = await requestPVE("/nodes", "GET"); + let allowedNodes = await requestAPI("/user/nodes", "GET"); + clusterNodes.data.forEach((element) => { + if (element.status === "online" && allowedNodes.includes(element.node)) { nodeSelect.add(new Option(element.node)); } });