separate disk and resource population
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
a8f9c67711
commit
7b712ad80b
@ -7,6 +7,7 @@ let diskMetaData = resources.disk;
|
|||||||
let node;
|
let node;
|
||||||
let type;
|
let type;
|
||||||
let vmid;
|
let vmid;
|
||||||
|
let config;
|
||||||
|
|
||||||
async function init () {
|
async function init () {
|
||||||
let cookie = document.cookie;
|
let cookie = document.cookie;
|
||||||
@ -18,20 +19,19 @@ async function init () {
|
|||||||
node = uriData.node;
|
node = uriData.node;
|
||||||
type = uriData.type;
|
type = uriData.type;
|
||||||
vmid = uriData.vmid;
|
vmid = uriData.vmid;
|
||||||
await populateResources();
|
|
||||||
|
config = await requestPVE(`/nodes/${node}/${type}/${vmid}/config`, "GET");
|
||||||
|
|
||||||
|
populateResources();
|
||||||
|
populateDisk();
|
||||||
|
|
||||||
let cancelButton = document.querySelector("#cancel");
|
let cancelButton = document.querySelector("#cancel");
|
||||||
cancelButton.addEventListener("click", () => {
|
cancelButton.addEventListener("click", () => {
|
||||||
goToPage("index.html");
|
goToPage("index.html");
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(diskMetaData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function populateResources () {
|
async function populateResources () {
|
||||||
let config = await requestPVE(`/nodes/${node}/${type}/${vmid}/config`, "GET");
|
|
||||||
console.log(config);
|
|
||||||
|
|
||||||
let name = type === "qemu" ? "name" : "hostname";
|
let name = type === "qemu" ? "name" : "hostname";
|
||||||
document.querySelector("#name").innerText = config.data[name];
|
document.querySelector("#name").innerText = config.data[name];
|
||||||
addResourceLine("resources", "images/resources/cpu.svg", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads"); // TODO add max from quota API
|
addResourceLine("resources", "images/resources/cpu.svg", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads"); // TODO add max from quota API
|
||||||
@ -40,22 +40,6 @@ async function populateResources () {
|
|||||||
if (type === "lxc") {
|
if (type === "lxc") {
|
||||||
addResourceLine("resources", "images/resources/swap.svg", "Swap", {type: "number", value: config.data.swap, min: 0, step: 1}, "MiB"); // TODO add max from quota API
|
addResourceLine("resources", "images/resources/swap.svg", "Swap", {type: "number", value: config.data.swap, min: 0, step: 1}, "MiB"); // TODO add max from quota API
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let i = 0; i < diskMetaData[type].prefixOrder.length; i++){
|
|
||||||
let prefix = diskMetaData[type].prefixOrder[i];
|
|
||||||
let busName = diskMetaData[type][prefix].name;
|
|
||||||
let disks = {};
|
|
||||||
Object.keys(config.data).forEach(element => {
|
|
||||||
if (element.startsWith(prefix)) {
|
|
||||||
disks[element.replace(prefix, "")] = config.data[element];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let ordered_keys = getOrderedUsed(disks);
|
|
||||||
ordered_keys.forEach(element => {
|
|
||||||
let disk = disks[element];
|
|
||||||
addDiskLine("disks", prefix, busName, element, disk);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addResourceLine (fieldset, iconHref, labelText, inputAttr, unitText=null) {
|
function addResourceLine (fieldset, iconHref, labelText, inputAttr, unitText=null) {
|
||||||
@ -85,6 +69,25 @@ function addResourceLine (fieldset, iconHref, labelText, inputAttr, unitText=nul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function populateDisk () {
|
||||||
|
document.querySelector("#disks").innerHTML = "";
|
||||||
|
for(let i = 0; i < diskMetaData[type].prefixOrder.length; i++){
|
||||||
|
let prefix = diskMetaData[type].prefixOrder[i];
|
||||||
|
let busName = diskMetaData[type][prefix].name;
|
||||||
|
let disks = {};
|
||||||
|
Object.keys(config.data).forEach(element => {
|
||||||
|
if (element.startsWith(prefix)) {
|
||||||
|
disks[element.replace(prefix, "")] = config.data[element];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let ordered_keys = getOrderedUsed(disks);
|
||||||
|
ordered_keys.forEach(element => {
|
||||||
|
let disk = disks[element];
|
||||||
|
addDiskLine("disks", prefix, busName, element, disk);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function addDiskLine (fieldset, busPrefix, busName, device, disk) {
|
async function addDiskLine (fieldset, busPrefix, busName, device, disk) {
|
||||||
let field = document.querySelector(`#${fieldset}`);
|
let field = document.querySelector(`#${fieldset}`);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user