2024-08-31 12:31:29 +00:00
|
|
|
import { requestPVE, requestAPI, goToPage, getURIData, resourcesConfig, setTitleAndHeader, bootConfig, setAppearance, setSVGSrc, setSVGAlt, mergeDeep, addResourceLine } from "./utils.js";
|
2023-06-29 22:20:15 +00:00
|
|
|
import { alert, dialog } from "./dialog.js";
|
|
|
|
|
|
|
|
window.addEventListener("DOMContentLoaded", init); // do the dumb thing where the disk config refreshes every second
|
|
|
|
|
|
|
|
const diskMetaData = resourcesConfig.disk;
|
|
|
|
const networkMetaData = resourcesConfig.network;
|
2024-08-31 12:31:29 +00:00
|
|
|
const pcieMetaData = resourcesConfig.pci;
|
2023-08-11 22:06:26 +00:00
|
|
|
const bootMetaData = bootConfig;
|
2023-06-29 22:20:15 +00:00
|
|
|
|
|
|
|
let node;
|
|
|
|
let type;
|
|
|
|
let vmid;
|
|
|
|
let config;
|
|
|
|
|
2024-08-31 12:31:29 +00:00
|
|
|
const resourceInputTypes = { // input types for each resource for config page
|
|
|
|
cpu: {
|
|
|
|
element: "select",
|
|
|
|
attributes: {}
|
|
|
|
},
|
|
|
|
cores: {
|
|
|
|
element: "input",
|
|
|
|
attributes: {
|
|
|
|
type: "number"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
memory: {
|
|
|
|
element: "input",
|
|
|
|
attributes: {
|
|
|
|
type: "number"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
swap: {
|
|
|
|
element: "input",
|
|
|
|
attributes: {
|
|
|
|
type: "number"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const resourcesConfigPage = mergeDeep({}, resourcesConfig, resourceInputTypes);
|
|
|
|
|
2023-06-29 22:20:15 +00:00
|
|
|
async function init () {
|
2024-07-17 19:49:13 +00:00
|
|
|
setAppearance();
|
2023-06-29 22:20:15 +00:00
|
|
|
setTitleAndHeader();
|
|
|
|
const cookie = document.cookie;
|
|
|
|
if (cookie === "") {
|
|
|
|
goToPage("login.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
const uriData = getURIData();
|
|
|
|
node = uriData.node;
|
|
|
|
type = uriData.type;
|
|
|
|
vmid = uriData.vmid;
|
|
|
|
|
|
|
|
await getConfig();
|
|
|
|
|
2024-08-31 12:31:29 +00:00
|
|
|
const name = type === "qemu" ? "name" : "hostname";
|
|
|
|
document.querySelector("#name").innerHTML = document.querySelector("#name").innerHTML.replace("%{vmname}", config.data[name]);
|
|
|
|
|
2023-06-29 22:20:15 +00:00
|
|
|
populateResources();
|
|
|
|
populateDisk();
|
|
|
|
populateNetworks();
|
|
|
|
populateDevices();
|
2023-08-09 21:52:55 +00:00
|
|
|
populateBoot();
|
2023-06-29 22:20:15 +00:00
|
|
|
|
|
|
|
document.querySelector("#exit").addEventListener("click", handleFormExit);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOrdered (keys) {
|
|
|
|
const orderedKeys = Object.keys(keys).sort((a, b) => {
|
|
|
|
return parseInt(a) - parseInt(b);
|
|
|
|
}); // ordered integer list
|
|
|
|
return orderedKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getConfig () {
|
|
|
|
config = await requestPVE(`/nodes/${node}/${type}/${vmid}/config`, "GET");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function populateResources () {
|
2024-08-31 12:31:29 +00:00
|
|
|
const field = document.querySelector("#resources");
|
2023-06-29 22:20:15 +00:00
|
|
|
if (type === "qemu") {
|
2024-10-01 18:19:59 +00:00
|
|
|
const global = (await requestAPI("/global/config/resources")).resources;
|
2023-06-29 22:20:15 +00:00
|
|
|
const user = await requestAPI("/user/config/resources");
|
|
|
|
let options = [];
|
2023-11-15 20:18:01 +00:00
|
|
|
const globalCPU = global.cpu;
|
|
|
|
const userCPU = node in user.cpu.nodes ? user.cpu.nodes[node] : user.cpu.global;
|
|
|
|
if (globalCPU.whitelist) {
|
|
|
|
userCPU.forEach((userType) => {
|
2023-09-11 19:04:07 +00:00
|
|
|
options.push(userType.name);
|
|
|
|
});
|
|
|
|
options = options.sort((a, b) => {
|
2023-06-29 22:20:15 +00:00
|
|
|
return a.localeCompare(b);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const supported = await requestPVE(`/nodes/${node}/capabilities/qemu/cpu`);
|
2023-09-11 19:04:07 +00:00
|
|
|
supported.data.forEach((supportedType) => {
|
2023-11-15 20:18:01 +00:00
|
|
|
if (!userCPU.some((userType) => supportedType.name === userType.name)) {
|
2023-09-11 19:04:07 +00:00
|
|
|
options.push(supportedType.name);
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
options = options.sort((a, b) => {
|
|
|
|
return a.localeCompare(b);
|
|
|
|
});
|
|
|
|
}
|
2024-08-31 12:31:29 +00:00
|
|
|
addResourceLine(resourcesConfigPage, field, "cpu", { value: config.data.cpu, options });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
2024-08-31 12:31:29 +00:00
|
|
|
addResourceLine(resourcesConfigPage, field, "cores", { value: config.data.cores, min: 1, max: 8192 });
|
|
|
|
addResourceLine(resourcesConfigPage, field, "memory", { value: config.data.memory, min: 16, step: 1 });
|
2023-06-29 22:20:15 +00:00
|
|
|
if (type === "lxc") {
|
2024-08-31 12:31:29 +00:00
|
|
|
addResourceLine(resourcesConfigPage, field, "swap", { value: config.data.swap, min: 0, step: 1 });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function populateDisk () {
|
|
|
|
document.querySelector("#disks").innerHTML = "";
|
|
|
|
for (let i = 0; i < diskMetaData[type].prefixOrder.length; i++) {
|
|
|
|
const prefix = diskMetaData[type].prefixOrder[i];
|
|
|
|
const busName = diskMetaData[type][prefix].name;
|
|
|
|
const disks = {};
|
|
|
|
Object.keys(config.data).forEach((element) => {
|
|
|
|
if (element.startsWith(prefix)) {
|
|
|
|
disks[element.replace(prefix, "")] = config.data[element];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const orderedKeys = getOrdered(disks);
|
|
|
|
orderedKeys.forEach((element) => {
|
|
|
|
const disk = disks[element];
|
|
|
|
addDiskLine("disks", prefix, busName, element, disk);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
document.querySelector("#disk-add").addEventListener("click", handleDiskAdd);
|
|
|
|
|
|
|
|
if (type === "qemu") {
|
|
|
|
document.querySelector("#cd-add").classList.remove("none");
|
|
|
|
document.querySelector("#cd-add").addEventListener("click", handleCDAdd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDiskLine (fieldset, busPrefix, busName, device, diskDetails) {
|
|
|
|
const field = document.querySelector(`#${fieldset}`);
|
|
|
|
|
|
|
|
const diskName = `${busName} ${device}`;
|
|
|
|
const diskID = `${busPrefix}${device}`;
|
|
|
|
|
|
|
|
// Set the disk icon, either drive.svg or disk.svg
|
2024-07-24 19:32:40 +00:00
|
|
|
const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
|
|
setSVGSrc(icon, diskMetaData[type][busPrefix].icon);
|
|
|
|
setSVGAlt(icon, diskName);
|
2023-06-29 22:20:15 +00:00
|
|
|
icon.dataset.disk = diskID;
|
|
|
|
field.append(icon);
|
|
|
|
|
|
|
|
// Add a label for the disk bus and device number
|
2023-09-07 02:44:11 +00:00
|
|
|
const diskLabel = document.createElement("p");
|
2023-06-29 22:20:15 +00:00
|
|
|
diskLabel.innerText = diskName;
|
|
|
|
diskLabel.dataset.disk = diskID;
|
|
|
|
field.append(diskLabel);
|
|
|
|
|
|
|
|
// Add text of the disk configuration
|
|
|
|
const diskDesc = document.createElement("p");
|
|
|
|
diskDesc.innerText = diskDetails;
|
|
|
|
diskDesc.dataset.disk = diskID;
|
|
|
|
diskDesc.style.overflowX = "hidden";
|
|
|
|
diskDesc.style.whiteSpace = "nowrap";
|
|
|
|
field.append(diskDesc);
|
|
|
|
|
|
|
|
const actionDiv = document.createElement("div");
|
|
|
|
diskMetaData.actionBarOrder.forEach((element) => {
|
2024-07-24 19:32:40 +00:00
|
|
|
const action = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
if (element === "detach_attach" && diskMetaData[type][busPrefix].actions.includes("attach")) { // attach
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(action, diskMetaData.actions.attach.src);
|
|
|
|
setSVGAlt(action, diskMetaData.actions.attach.title);
|
2023-06-29 22:20:15 +00:00
|
|
|
action.title = "Attach Disk";
|
|
|
|
action.addEventListener("click", handleDiskAttach);
|
|
|
|
action.classList.add("clickable");
|
|
|
|
}
|
|
|
|
else if (element === "detach_attach" && diskMetaData[type][busPrefix].actions.includes("detach")) { // detach
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(action, diskMetaData.actions.detach.src);
|
|
|
|
setSVGAlt(action, diskMetaData.actions.detach.title);
|
2023-06-29 22:20:15 +00:00
|
|
|
action.addEventListener("click", handleDiskDetach);
|
|
|
|
action.classList.add("clickable");
|
|
|
|
}
|
|
|
|
else if (element === "delete") {
|
|
|
|
const active = diskMetaData[type][busPrefix].actions.includes(element) ? "active" : "inactive"; // resize
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(action, `images/actions/delete-${active}.svg`);
|
|
|
|
setSVGAlt(action, "Delete Disk");
|
2023-06-29 22:20:15 +00:00
|
|
|
if (active === "active") {
|
|
|
|
action.addEventListener("click", handleDiskDelete);
|
|
|
|
action.classList.add("clickable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const active = diskMetaData[type][busPrefix].actions.includes(element) ? "active" : "inactive"; // resize
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(action, `images/actions/disk/${element}-${active}.svg`);
|
2023-06-29 22:20:15 +00:00
|
|
|
if (active === "active") {
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGAlt(action, `${element.charAt(0).toUpperCase()}${element.slice(1)} Disk`);
|
2023-06-29 22:20:15 +00:00
|
|
|
if (element === "move") {
|
|
|
|
action.addEventListener("click", handleDiskMove);
|
|
|
|
}
|
|
|
|
else if (element === "resize") {
|
|
|
|
action.addEventListener("click", handleDiskResize);
|
|
|
|
}
|
|
|
|
action.classList.add("clickable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
action.dataset.disk = diskID;
|
|
|
|
actionDiv.append(action);
|
|
|
|
});
|
|
|
|
field.append(actionDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDiskDetach () {
|
2023-08-16 23:14:42 +00:00
|
|
|
const disk = this.dataset.disk;
|
|
|
|
const header = `Detach ${disk}`;
|
2023-11-14 00:09:41 +00:00
|
|
|
const body = `<p>Are you sure you want to detach disk ${disk}</p>`;
|
2023-06-29 22:20:15 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-disk="${disk}"]`), "images/status/loading.svg");
|
2023-08-16 23:14:42 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/disk/${disk}/detach`, "POST");
|
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
deleteBootLine(`boot-${disk}`);
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDiskAttach () {
|
|
|
|
const header = `Attach ${this.dataset.disk}`;
|
2023-11-14 00:09:41 +00:00
|
|
|
const body = `
|
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
|
|
|
<label for="device">${type === "qemu" ? "SATA" : "MP"}</label>
|
2024-08-31 12:31:29 +00:00
|
|
|
<input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="${type === "qemu" ? "5" : "255"}" required>
|
2023-11-14 00:09:41 +00:00
|
|
|
</form>
|
|
|
|
`;
|
2023-06-29 22:20:15 +00:00
|
|
|
|
|
|
|
dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
|
|
|
const device = form.get("device");
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-disk="${this.dataset.disk}"]`), "images/status/loading.svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
const body = {
|
|
|
|
source: this.dataset.disk.replace("unused", "")
|
|
|
|
};
|
2023-08-16 23:14:42 +00:00
|
|
|
const prefix = type === "qemu" ? "sata" : "mp";
|
|
|
|
const disk = `${prefix}${device}`;
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/disk/${disk}/attach`, "POST", body);
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-08-22 21:23:14 +00:00
|
|
|
addBootLine("disabled", { id: disk, prefix, value: disk, detail: config.data[disk] });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDiskResize () {
|
|
|
|
const header = `Resize ${this.dataset.disk}`;
|
2023-11-14 00:09:41 +00:00
|
|
|
const body = `
|
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
|
|
|
<label for="size-increment">Size Increment (GiB)</label>
|
2024-08-31 12:31:29 +00:00
|
|
|
<input class="w3-input w3-border" name="size-increment" id="size-increment" type="number" min="0" max="131072">
|
2023-11-14 00:09:41 +00:00
|
|
|
</form>
|
|
|
|
`;
|
2023-06-29 22:20:15 +00:00
|
|
|
|
|
|
|
dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
2023-08-16 23:14:42 +00:00
|
|
|
const disk = this.dataset.disk;
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-disk="${disk}"]`), "images/status/loading.svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
const body = {
|
|
|
|
size: form.get("size-increment")
|
|
|
|
};
|
2023-08-16 23:14:42 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/disk/${disk}/resize`, "POST", body);
|
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
const prefix = bootMetaData.eligiblePrefixes.find((pref) => disk.startsWith(pref));
|
2023-08-22 21:23:14 +00:00
|
|
|
updateBootLine(`boot-${disk}`, { id: disk, prefix, value: disk, detail: config.data[disk] });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDiskMove () {
|
|
|
|
const content = type === "qemu" ? "images" : "rootdir";
|
|
|
|
const storage = await requestPVE(`/nodes/${node}/storage`, "GET");
|
|
|
|
|
|
|
|
const header = `Move ${this.dataset.disk}`;
|
|
|
|
|
|
|
|
let options = "";
|
|
|
|
storage.data.forEach((element) => {
|
|
|
|
if (element.content.includes(content)) {
|
|
|
|
options += `<option value="${element.storage}">${element.storage}</option>"`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const select = `<label for="storage-select">Storage</label><select class="w3-select w3-border" name="storage-select" id="storage-select"><option hidden disabled selected value></option>${options}</select>`;
|
|
|
|
|
|
|
|
const body = `
|
2023-11-14 00:09:41 +00:00
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
|
|
|
${select}
|
|
|
|
<label for="delete-check">Delete Source</label><input class="w3-input w3-border" name="delete-check" id="delete-check" type="checkbox" checked required>
|
|
|
|
</form>
|
2023-06-29 22:20:15 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
2023-08-16 23:14:42 +00:00
|
|
|
const disk = this.dataset.disk;
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-disk="${disk}"]`), "images/status/loading.svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
const body = {
|
|
|
|
storage: form.get("storage-select"),
|
|
|
|
delete: form.get("delete-check") === "on" ? "1" : "0"
|
|
|
|
};
|
2023-08-16 23:14:42 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/disk/${disk}/move`, "POST", body);
|
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
const prefix = bootMetaData.eligiblePrefixes.find((pref) => disk.startsWith(pref));
|
|
|
|
updateBootLine(`boot-${disk}`, { id: disk, prefix, value: config.data[disk] });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDiskDelete () {
|
2023-08-16 23:14:42 +00:00
|
|
|
const disk = this.dataset.disk;
|
|
|
|
const header = `Delete ${disk}`;
|
2023-11-14 00:09:41 +00:00
|
|
|
const body = `<p>Are you sure you want to <strong>delete</strong> disk${disk}</p>`;
|
2023-06-29 22:20:15 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-disk="${disk}"]`), "images/status/loading.svg");
|
2023-08-16 23:14:42 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/disk/${disk}/delete`, "DELETE");
|
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
deleteBootLine(`boot-${disk}`);
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDiskAdd () {
|
|
|
|
const content = type === "qemu" ? "images" : "rootdir";
|
|
|
|
const storage = await requestPVE(`/nodes/${node}/storage`, "GET");
|
|
|
|
|
|
|
|
const header = "Create New Disk";
|
|
|
|
|
|
|
|
let options = "";
|
|
|
|
storage.data.forEach((element) => {
|
|
|
|
if (element.content.includes(content)) {
|
|
|
|
options += `<option value="${element.storage}">${element.storage}</option>"`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const select = `<label for="storage-select">Storage</label><select class="w3-select w3-border" name="storage-select" id="storage-select" required><option hidden disabled selected value></option>${options}</select>`;
|
|
|
|
|
|
|
|
const body = `
|
2023-11-14 00:09:41 +00:00
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
2024-08-31 12:31:29 +00:00
|
|
|
<label for="device">${type === "qemu" ? "SATA" : "MP"}</label><input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="${type === "qemu" ? "5" : "255"}" value="0" required>
|
2023-11-14 00:09:41 +00:00
|
|
|
${select}
|
2024-08-31 12:31:29 +00:00
|
|
|
<label for="size">Size (GiB)</label><input class="w3-input w3-border" name="size" id="size" type="number" min="0" max="131072" required>
|
2023-11-14 00:09:41 +00:00
|
|
|
</form>
|
2023-06-29 22:20:15 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
|
|
|
const body = {
|
|
|
|
storage: form.get("storage-select"),
|
|
|
|
size: form.get("size")
|
|
|
|
};
|
2023-08-16 23:14:42 +00:00
|
|
|
const id = form.get("device");
|
|
|
|
const prefix = type === "qemu" ? "sata" : "mp";
|
|
|
|
const disk = `${prefix}${id}`;
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/disk/${disk}/create`, "POST", body);
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-08-22 21:23:14 +00:00
|
|
|
addBootLine("disabled", { id: disk, prefix, value: disk, detail: config.data[disk] });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleCDAdd () {
|
2024-04-16 21:38:25 +00:00
|
|
|
const isos = await requestAPI("/user/vm-isos", "GET");
|
2023-06-29 22:20:15 +00:00
|
|
|
|
|
|
|
const header = "Add a CDROM";
|
|
|
|
|
|
|
|
const body = `
|
2023-11-14 00:09:41 +00:00
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
2024-08-31 12:31:29 +00:00
|
|
|
<label for="device">IDE</label><input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="3" required>
|
2023-11-14 00:09:41 +00:00
|
|
|
<label for="iso-select">Image</label><select class="w3-select w3-border" name="iso-select" id="iso-select" required></select>
|
|
|
|
</form>
|
2023-06-29 22:20:15 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const d = dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
|
|
|
const body = {
|
|
|
|
iso: form.get("iso-select")
|
|
|
|
};
|
2023-07-04 04:41:39 +00:00
|
|
|
const disk = `ide${form.get("device")}`;
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/disk/${disk}/create`, "POST", body);
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-08-22 21:23:14 +00:00
|
|
|
addBootLine("disabled", { id: disk, prefix: "ide", value: disk, detail: config.data[disk] });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-04-16 21:38:25 +00:00
|
|
|
const isoSelect = d.querySelector("#iso-select");
|
|
|
|
|
|
|
|
for (const iso of isos) {
|
2024-04-27 03:50:29 +00:00
|
|
|
isoSelect.append(new Option(iso.name, iso.volid));
|
2024-04-16 21:38:25 +00:00
|
|
|
}
|
|
|
|
isoSelect.selectedIndex = -1;
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function populateNetworks () {
|
|
|
|
document.querySelector("#networks").innerHTML = "";
|
|
|
|
const networks = {};
|
|
|
|
const prefix = networkMetaData.prefix;
|
|
|
|
Object.keys(config.data).forEach((element) => {
|
|
|
|
if (element.startsWith(prefix)) {
|
|
|
|
networks[element.replace(prefix, "")] = config.data[element];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const orderedKeys = getOrdered(networks);
|
|
|
|
orderedKeys.forEach((element) => {
|
|
|
|
addNetworkLine("networks", prefix, element, networks[element]);
|
|
|
|
});
|
|
|
|
|
|
|
|
document.querySelector("#network-add").addEventListener("click", handleNetworkAdd);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addNetworkLine (fieldset, prefix, netID, netDetails) {
|
|
|
|
const field = document.querySelector(`#${fieldset}`);
|
|
|
|
|
2024-07-24 19:32:40 +00:00
|
|
|
const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
2024-08-31 12:31:29 +00:00
|
|
|
setSVGSrc(icon, networkMetaData.icon);
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGAlt(icon, `${prefix}${netID}`);
|
2023-06-29 22:20:15 +00:00
|
|
|
icon.dataset.network = netID;
|
|
|
|
icon.dataset.values = netDetails;
|
|
|
|
field.appendChild(icon);
|
|
|
|
|
2023-09-07 02:44:11 +00:00
|
|
|
const netLabel = document.createElement("p");
|
2023-06-29 22:20:15 +00:00
|
|
|
netLabel.innerText = `${prefix}${netID}`;
|
|
|
|
netLabel.dataset.network = netID;
|
|
|
|
netLabel.dataset.values = netDetails;
|
|
|
|
field.append(netLabel);
|
|
|
|
|
|
|
|
const netDesc = document.createElement("p");
|
|
|
|
netDesc.innerText = netDetails;
|
|
|
|
netDesc.dataset.network = netID;
|
|
|
|
netDesc.dataset.values = netDetails;
|
|
|
|
netDesc.style.overflowX = "hidden";
|
|
|
|
netDesc.style.whiteSpace = "nowrap";
|
|
|
|
field.append(netDesc);
|
|
|
|
|
|
|
|
const actionDiv = document.createElement("div");
|
|
|
|
|
2024-07-24 19:32:40 +00:00
|
|
|
const configBtn = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
configBtn.classList.add("clickable");
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(configBtn, "images/actions/network/config.svg");
|
|
|
|
setSVGAlt(configBtn, "Config Interface");
|
2023-06-29 22:20:15 +00:00
|
|
|
configBtn.addEventListener("click", handleNetworkConfig);
|
|
|
|
configBtn.dataset.network = netID;
|
|
|
|
configBtn.dataset.values = netDetails;
|
|
|
|
actionDiv.appendChild(configBtn);
|
|
|
|
|
2024-07-24 19:32:40 +00:00
|
|
|
const deleteBtn = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
deleteBtn.classList.add("clickable");
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(deleteBtn, "images/actions/delete-active.svg");
|
|
|
|
setSVGAlt(deleteBtn, "Delete Interface");
|
2023-06-29 22:20:15 +00:00
|
|
|
deleteBtn.addEventListener("click", handleNetworkDelete);
|
|
|
|
deleteBtn.dataset.network = netID;
|
|
|
|
deleteBtn.dataset.values = netDetails;
|
|
|
|
actionDiv.appendChild(deleteBtn);
|
|
|
|
|
|
|
|
field.append(actionDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleNetworkConfig () {
|
|
|
|
const netID = this.dataset.network;
|
|
|
|
const netDetails = this.dataset.values;
|
|
|
|
const header = `Edit net${netID}`;
|
2023-11-14 00:09:41 +00:00
|
|
|
const body = `
|
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
|
|
|
<label for="rate">Rate Limit (MB/s)</label><input type="number" id="rate" name="rate" class="w3-input w3-border">
|
|
|
|
</form>
|
|
|
|
`;
|
2023-06-29 22:20:15 +00:00
|
|
|
|
|
|
|
const d = dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-network="${netID}"]`), "images/status/loading.svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
const body = {
|
|
|
|
rate: form.get("rate")
|
|
|
|
};
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/net/net${netID}/modify`, "POST", body);
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateNetworks();
|
2023-11-14 00:09:41 +00:00
|
|
|
const id = `net${netID}`;
|
|
|
|
updateBootLine(`boot-net${netID}`, { id, prefix: "net", value: id, detail: config.data[`net${netID}`] });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
d.querySelector("#rate").value = netDetails.split("rate=")[1].split(",")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleNetworkDelete () {
|
|
|
|
const netID = this.dataset.network;
|
|
|
|
const header = `Delete net${netID}`;
|
|
|
|
const body = "";
|
|
|
|
|
2023-07-06 04:53:47 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
2023-06-29 22:20:15 +00:00
|
|
|
if (result === "confirm") {
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-network="${netID}"]`), "images/status/loading.svg");
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/net/net${netID}/delete`, "DELETE");
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateNetworks();
|
|
|
|
deleteBootLine(`boot-net${netID}`);
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleNetworkAdd () {
|
|
|
|
const header = "Create Network Interface";
|
2023-11-14 00:09:41 +00:00
|
|
|
let body = `
|
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
|
|
|
<label for="netid">Interface ID</label><input type="number" id="netid" name="netid" class="w3-input w3-border">
|
|
|
|
<label for="rate">Rate Limit (MB/s)</label><input type="number" id="rate" name="rate" class="w3-input w3-border">
|
|
|
|
`;
|
2023-06-29 22:20:15 +00:00
|
|
|
if (type === "lxc") {
|
2024-08-31 12:31:29 +00:00
|
|
|
body += "<label for=\"name\">Interface Name</label><input type=\"text\" id=\"name\" name=\"name\" class=\"w3-input w3-border\">";
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
2023-11-14 00:09:41 +00:00
|
|
|
body += "</form>";
|
2023-06-29 22:20:15 +00:00
|
|
|
|
2023-07-06 04:53:47 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
2023-06-29 22:20:15 +00:00
|
|
|
if (result === "confirm") {
|
|
|
|
const body = {
|
|
|
|
rate: form.get("rate")
|
|
|
|
};
|
|
|
|
if (type === "lxc") {
|
|
|
|
body.name = form.get("name");
|
|
|
|
}
|
2023-07-04 04:41:39 +00:00
|
|
|
const netID = form.get("netid");
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/net/net${netID}/create`, "POST", body);
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateNetworks();
|
2023-08-22 21:23:14 +00:00
|
|
|
const id = `net${netID}`;
|
|
|
|
addBootLine("disabled", { id, prefix: "net", value: id, detail: config.data[`net${netID}`] });
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function populateDevices () {
|
|
|
|
if (type === "qemu") {
|
|
|
|
document.querySelector("#devices-card").classList.remove("none");
|
|
|
|
document.querySelector("#devices").innerHTML = "";
|
|
|
|
const devices = {};
|
|
|
|
const prefix = pcieMetaData.prefix;
|
|
|
|
Object.keys(config.data).forEach((element) => {
|
|
|
|
if (element.startsWith(prefix)) {
|
|
|
|
devices[element.replace(prefix, "")] = config.data[element];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const orderedKeys = getOrdered(devices);
|
|
|
|
orderedKeys.forEach(async (element) => {
|
2023-08-03 00:35:56 +00:00
|
|
|
const deviceData = await requestAPI(`/cluster/${node}/${type}/${vmid}/pci/hostpci${element}`, "GET");
|
2023-06-29 22:20:15 +00:00
|
|
|
addDeviceLine("devices", prefix, element, devices[element], deviceData.device_name);
|
|
|
|
});
|
|
|
|
|
|
|
|
document.querySelector("#device-add").addEventListener("click", handleDeviceAdd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDeviceLine (fieldset, prefix, deviceID, deviceDetails, deviceName) {
|
|
|
|
const field = document.querySelector(`#${fieldset}`);
|
|
|
|
|
2024-07-24 19:32:40 +00:00
|
|
|
const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
2024-08-31 12:31:29 +00:00
|
|
|
setSVGSrc(icon, pcieMetaData.icon);
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGAlt(icon, `${prefix}${deviceID}`);
|
2023-06-29 22:20:15 +00:00
|
|
|
icon.dataset.device = deviceID;
|
|
|
|
icon.dataset.values = deviceDetails;
|
|
|
|
icon.dataset.name = deviceName;
|
|
|
|
field.appendChild(icon);
|
|
|
|
|
|
|
|
const deviceLabel = document.createElement("p");
|
|
|
|
deviceLabel.innerText = deviceName;
|
|
|
|
deviceLabel.dataset.device = deviceID;
|
|
|
|
deviceLabel.dataset.values = deviceDetails;
|
|
|
|
deviceLabel.dataset.name = deviceName;
|
|
|
|
deviceLabel.style.overflowX = "hidden";
|
|
|
|
deviceLabel.style.whiteSpace = "nowrap";
|
|
|
|
field.append(deviceLabel);
|
|
|
|
|
|
|
|
const actionDiv = document.createElement("div");
|
|
|
|
|
2024-07-24 19:32:40 +00:00
|
|
|
const configBtn = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
configBtn.classList.add("clickable");
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(configBtn, "images/actions/device/config.svg");
|
|
|
|
setSVGAlt(configBtn, "Config Device");
|
2023-06-29 22:20:15 +00:00
|
|
|
configBtn.addEventListener("click", handleDeviceConfig);
|
|
|
|
configBtn.dataset.device = deviceID;
|
|
|
|
configBtn.dataset.values = deviceDetails;
|
|
|
|
configBtn.dataset.name = deviceName;
|
|
|
|
actionDiv.appendChild(configBtn);
|
|
|
|
|
2024-07-24 19:32:40 +00:00
|
|
|
const deleteBtn = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
deleteBtn.classList.add("clickable");
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(deleteBtn, "images/actions/delete-active.svg");
|
|
|
|
setSVGAlt(deleteBtn, "Delete Device");
|
2023-06-29 22:20:15 +00:00
|
|
|
deleteBtn.addEventListener("click", handleDeviceDelete);
|
|
|
|
deleteBtn.dataset.device = deviceID;
|
|
|
|
deleteBtn.dataset.values = deviceDetails;
|
|
|
|
deleteBtn.dataset.name = deviceName;
|
|
|
|
actionDiv.appendChild(deleteBtn);
|
|
|
|
|
|
|
|
field.append(actionDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDeviceConfig () {
|
|
|
|
const deviceID = this.dataset.device;
|
|
|
|
const deviceDetails = this.dataset.values;
|
|
|
|
const deviceName = this.dataset.name;
|
|
|
|
const header = `Edit Expansion Card ${deviceID}`;
|
2023-11-14 00:09:41 +00:00
|
|
|
const body = `
|
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
|
|
|
<label for="device">Device</label><select id="device" name="device" required></select><label for="pcie">PCI-Express</label><input type="checkbox" id="pcie" name="pcie" class="w3-input w3-border">
|
|
|
|
</form>
|
|
|
|
`;
|
2023-06-29 22:20:15 +00:00
|
|
|
|
|
|
|
const d = dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-device="${deviceID}"]`), "images/status/loading.svg");
|
2023-06-29 22:20:15 +00:00
|
|
|
const body = {
|
|
|
|
device: form.get("device"),
|
|
|
|
pcie: form.get("pcie") ? 1 : 0
|
|
|
|
};
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/pci/hostpci${deviceID}/modify`, "POST", body);
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDevices();
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-03 00:35:56 +00:00
|
|
|
const availDevices = await requestAPI(`/cluster/${node}/pci`, "GET");
|
2023-06-29 22:20:15 +00:00
|
|
|
d.querySelector("#device").append(new Option(deviceName, deviceDetails.split(",")[0]));
|
|
|
|
for (const availDevice of availDevices) {
|
|
|
|
d.querySelector("#device").append(new Option(availDevice.device_name, availDevice.id));
|
|
|
|
}
|
|
|
|
d.querySelector("#pcie").checked = deviceDetails.includes("pcie=1");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDeviceDelete () {
|
|
|
|
const deviceID = this.dataset.device;
|
|
|
|
const header = `Remove Expansion Card ${deviceID}`;
|
|
|
|
const body = "";
|
|
|
|
|
2023-07-06 04:53:47 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
2023-06-29 22:20:15 +00:00
|
|
|
if (result === "confirm") {
|
2024-07-24 19:32:40 +00:00
|
|
|
setSVGSrc(document.querySelector(`svg[data-device="${deviceID}"]`), "images/status/loading.svg");
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/pci/hostpci${deviceID}/delete`, "DELETE");
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDevices();
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDeviceAdd () {
|
|
|
|
const header = "Add Expansion Card";
|
2023-11-14 00:09:41 +00:00
|
|
|
const body = `
|
|
|
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
|
|
|
<label for="device">Device</label><select id="device" name="device" required></select><label for="pcie">PCI-Express</label><input type="checkbox" id="pcie" name="pcie" class="w3-input w3-border">
|
|
|
|
</form>
|
|
|
|
`;
|
2023-06-29 22:20:15 +00:00
|
|
|
|
|
|
|
const d = dialog(header, body, async (result, form) => {
|
|
|
|
if (result === "confirm") {
|
|
|
|
const body = {
|
|
|
|
device: form.get("device"),
|
|
|
|
pcie: form.get("pcie") ? 1 : 0
|
|
|
|
};
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/pci/create`, "POST", body);
|
2023-08-16 23:14:42 +00:00
|
|
|
if (result.status !== 200) {
|
2023-06-29 22:20:15 +00:00
|
|
|
alert(result.error);
|
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDevices();
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-03 00:35:56 +00:00
|
|
|
const availDevices = await requestAPI(`/cluster/${node}/pci`, "GET");
|
2023-06-29 22:20:15 +00:00
|
|
|
for (const availDevice of availDevices) {
|
|
|
|
d.querySelector("#device").append(new Option(availDevice.device_name, availDevice.id));
|
|
|
|
}
|
|
|
|
d.querySelector("#pcie").checked = true;
|
|
|
|
}
|
|
|
|
|
2023-08-11 22:06:26 +00:00
|
|
|
async function populateBoot () {
|
|
|
|
if (type === "qemu") {
|
|
|
|
document.querySelector("#boot-card").classList.remove("none");
|
2023-08-14 23:42:02 +00:00
|
|
|
document.querySelector("#enabled").title = "Enabled";
|
|
|
|
document.querySelector("#disabled").title = "Disabled";
|
2023-08-16 23:14:42 +00:00
|
|
|
let order = [];
|
|
|
|
if (config.data.boot.startsWith("order=")) {
|
|
|
|
order = config.data.boot.replace("order=", "").split(";");
|
|
|
|
}
|
2023-08-11 22:06:26 +00:00
|
|
|
const bootable = { disabled: [] };
|
|
|
|
const eligible = bootMetaData.eligiblePrefixes;
|
|
|
|
for (let i = 0; i < order.length; i++) {
|
2023-08-16 23:14:42 +00:00
|
|
|
const element = order[i];
|
2023-08-11 22:06:26 +00:00
|
|
|
const prefix = eligible.find((pref) => order[i].startsWith(pref));
|
2023-08-19 03:32:52 +00:00
|
|
|
const detail = config.data[element];
|
2023-08-22 21:23:14 +00:00
|
|
|
bootable[i] = { id: element, value: element, prefix, detail };
|
2023-08-11 22:06:26 +00:00
|
|
|
}
|
|
|
|
Object.keys(config.data).forEach((element) => {
|
|
|
|
const prefix = eligible.find((pref) => element.startsWith(pref));
|
2023-08-19 03:32:52 +00:00
|
|
|
const detail = config.data[element];
|
2023-08-11 22:06:26 +00:00
|
|
|
if (prefix && !order.includes(element)) {
|
2023-08-22 21:23:14 +00:00
|
|
|
bootable.disabled.push({ id: element, value: element, prefix, detail });
|
2023-08-11 22:06:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.keys(bootable).sort();
|
|
|
|
Object.keys(bootable).forEach((element) => {
|
|
|
|
if (element !== "disabled") {
|
|
|
|
addBootLine("enabled", bootable[element], document.querySelector("#enabled-spacer"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bootable.disabled.forEach((item) => {
|
|
|
|
addBootLine("disabled", item, document.querySelector("#disabled-spacer"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-16 23:14:42 +00:00
|
|
|
function addBootLine (container, data, before = null) {
|
2023-08-14 23:42:02 +00:00
|
|
|
const item = document.createElement("draggable-item");
|
2023-08-16 23:14:42 +00:00
|
|
|
item.data = data;
|
2023-08-14 23:42:02 +00:00
|
|
|
item.innerHTML = `
|
2023-08-29 21:26:57 +00:00
|
|
|
<div style="display: grid; grid-template-columns: auto auto 8ch 1fr; column-gap: 10px; align-items: center;">
|
2024-08-31 12:31:29 +00:00
|
|
|
<svg id="drag" role="application" aria-label="drag icon"><title>drag icon</title><use href="images/actions/drag.svg#symb"></use></svg>
|
|
|
|
<svg role="application" aria-label="${bootMetaData[data.prefix].alt}"><title>${bootMetaData[data.prefix].alt}</title><use href="${bootMetaData[data.prefix].icon}#symb"></use></svg>
|
2023-08-29 21:26:57 +00:00
|
|
|
<p style="margin: 0px;">${data.id}</p>
|
|
|
|
<p style="margin: 0px; overflow-x: hidden; white-space: nowrap;">${data.detail}</p>
|
|
|
|
</div>
|
2023-08-14 23:42:02 +00:00
|
|
|
`;
|
2023-08-16 23:14:42 +00:00
|
|
|
item.id = `boot-${data.id}`;
|
2023-08-11 22:06:26 +00:00
|
|
|
if (before) {
|
2023-08-16 23:14:42 +00:00
|
|
|
document.querySelector(`#${container}`).insertBefore(item, before);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.querySelector(`#${container}`).append(item);
|
|
|
|
}
|
|
|
|
item.container = container;
|
2023-08-22 21:23:14 +00:00
|
|
|
item.value = data.value;
|
2023-08-16 23:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteBootLine (id) {
|
2023-09-07 21:42:19 +00:00
|
|
|
const query = `#${id}`;
|
2023-08-23 22:55:48 +00:00
|
|
|
const enabled = document.querySelector("#enabled");
|
|
|
|
const disabled = document.querySelector("#disabled");
|
2023-09-07 21:42:19 +00:00
|
|
|
const inEnabled = enabled.querySelector(query);
|
|
|
|
const inDisabled = disabled.querySelector(query);
|
|
|
|
if (inEnabled) {
|
|
|
|
enabled.removeChild(inEnabled);
|
2023-08-22 21:23:14 +00:00
|
|
|
}
|
2023-09-07 21:42:19 +00:00
|
|
|
if (inDisabled) {
|
|
|
|
disabled.removeChild(inDisabled);
|
2023-08-22 21:23:14 +00:00
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateBootLine (id, newData) {
|
2023-08-23 22:55:48 +00:00
|
|
|
const enabled = document.querySelector("#enabled");
|
|
|
|
const disabled = document.querySelector("#disabled");
|
2023-08-22 21:23:14 +00:00
|
|
|
let element = null;
|
2023-11-14 00:09:41 +00:00
|
|
|
if (enabled.querySelector(`#${id}`)) {
|
|
|
|
element = enabled.querySelector(`#${id}`);
|
2023-08-22 21:23:14 +00:00
|
|
|
}
|
2023-11-14 00:09:41 +00:00
|
|
|
if (disabled.querySelector(`#${id}`)) {
|
|
|
|
element = disabled.querySelector(`#${id}`);
|
2023-08-22 21:23:14 +00:00
|
|
|
}
|
2023-08-16 23:14:42 +00:00
|
|
|
if (element) {
|
|
|
|
const container = element.container;
|
|
|
|
const before = element.nextSibling;
|
|
|
|
deleteBootLine(id);
|
|
|
|
addBootLine(container, newData, before);
|
|
|
|
return true;
|
2023-08-11 22:06:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-08-16 23:14:42 +00:00
|
|
|
return false;
|
2023-08-11 22:06:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-29 22:20:15 +00:00
|
|
|
async function handleFormExit () {
|
|
|
|
const body = {
|
|
|
|
cores: document.querySelector("#cores").value,
|
|
|
|
memory: document.querySelector("#ram").value
|
|
|
|
};
|
|
|
|
if (type === "lxc") {
|
|
|
|
body.swap = document.querySelector("#swap").value;
|
|
|
|
}
|
|
|
|
else if (type === "qemu") {
|
|
|
|
body.proctype = document.querySelector("#proctype").value;
|
2023-08-19 03:32:52 +00:00
|
|
|
body.boot = document.querySelector("#enabled").value;
|
2023-06-29 22:20:15 +00:00
|
|
|
}
|
2023-08-03 00:35:56 +00:00
|
|
|
const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/resources`, "POST", body);
|
2023-06-29 22:20:15 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
goToPage("index.html");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert(result.error);
|
|
|
|
}
|
|
|
|
}
|