add lxc config form populating

This commit is contained in:
Arthur Lu 2022-12-21 15:06:26 -08:00
parent 912b038136
commit 72f356d50a

View File

@ -24,10 +24,12 @@ async function populateForm (node, type, vmid) {
let config = await request(`/nodes/${node}/${type}/${vmid}/config`); let config = await request(`/nodes/${node}/${type}/${vmid}/config`);
console.log(config); console.log(config);
addFormLine("name", "Name", {type: "text", value: config.data.name}); let name = type === "qemu" ? "hostname" : "name";
addFormLine("name", "Name", {type: "text", value: config.data[name]});
addFormLine("resources", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads"); addFormLine("resources", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads");
addFormLine("resources", "Memory", {type: "number", value: config.data.memory / 1024, min: 16}, "GiB"); addFormLine("resources", "Memory", {type: "number", value: config.data.memory / 1024, min: 16}, "GiB");
if (type === "qemu") {
let i = 0; let i = 0;
while(Object.hasOwn(config.data, `sata${i}`)){ while(Object.hasOwn(config.data, `sata${i}`)){
let sata = config.data[`sata${i}`]; let sata = config.data[`sata${i}`];
@ -39,6 +41,15 @@ async function populateForm (node, type, vmid) {
i++; i++;
} }
} }
else {
let rootfs = config.data.rootfs;
rootfs = `{"${rootfs.replaceAll(":", '":"').replaceAll("=", '":"').replaceAll(",", '","')}"}`;
rootfs = JSON.parse(rootfs);
let sizeNum = +(rootfs.size.replaceAll("G", "").replaceAll("M", ""));
let sizeUnit = rootfs.size.includes("G") ? "GiB" : "MiB";
addFormLine("resources", "rootfs", {type: "number", value: sizeUnit === "GiB" ? sizeNum.toFixed(3) : (sizeNum / 1024).toFixed(3), min: 0.016}, "GiB");
}
}
function addFormLine (fieldset, labelText, inputAttr, unitText=null) { function addFormLine (fieldset, labelText, inputAttr, unitText=null) {
let field = document.querySelector(`#${fieldset}`); let field = document.querySelector(`#${fieldset}`);