2023-05-16 15:18:36 +00:00
|
|
|
import {requestPVE, requestAPI, goToPage, getURIData, resources_config, setTitleAndHeader} from "./utils.js";
|
2023-05-12 21:26:26 +00:00
|
|
|
import {alert, dialog} from "./dialog.js";
|
2022-12-19 06:14:57 +00:00
|
|
|
|
2023-01-30 23:43:00 +00:00
|
|
|
window.addEventListener("DOMContentLoaded", init); // do the dumb thing where the disk config refreshes every second
|
2022-12-19 06:14:57 +00:00
|
|
|
|
2023-05-15 21:22:12 +00:00
|
|
|
let diskMetaData = resources_config.disk;
|
|
|
|
let networkMetaData = resources_config.network;
|
2023-01-11 10:57:37 +00:00
|
|
|
|
|
|
|
let node;
|
|
|
|
let type;
|
|
|
|
let vmid;
|
2023-01-26 19:48:41 +00:00
|
|
|
let config;
|
2023-01-11 10:57:37 +00:00
|
|
|
|
2022-12-19 06:14:57 +00:00
|
|
|
async function init () {
|
2023-05-16 15:18:36 +00:00
|
|
|
setTitleAndHeader();
|
2022-12-20 23:15:08 +00:00
|
|
|
let cookie = document.cookie;
|
|
|
|
if (cookie === "") {
|
|
|
|
goToPage("login.html");
|
|
|
|
}
|
|
|
|
|
2022-12-19 06:14:57 +00:00
|
|
|
let uriData = getURIData();
|
2023-01-11 10:57:37 +00:00
|
|
|
node = uriData.node;
|
|
|
|
type = uriData.type;
|
|
|
|
vmid = uriData.vmid;
|
2023-01-26 19:48:41 +00:00
|
|
|
|
2023-01-26 19:55:17 +00:00
|
|
|
await getConfig();
|
2023-01-26 19:48:41 +00:00
|
|
|
|
|
|
|
populateResources();
|
|
|
|
populateDisk();
|
2023-05-15 21:22:12 +00:00
|
|
|
populateNetworks();
|
2022-12-20 23:42:13 +00:00
|
|
|
|
2023-02-17 22:17:20 +00:00
|
|
|
document.querySelector("#exit").addEventListener("click", handleFormExit);
|
2022-12-20 00:13:43 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 21:22:12 +00:00
|
|
|
function getOrdered(keys){
|
|
|
|
let ordered_keys = Object.keys(keys).sort((a,b) => {parseInt(a) - parseInt(b)}); // ordered integer list
|
|
|
|
return ordered_keys;
|
|
|
|
}
|
|
|
|
|
2023-01-26 19:55:17 +00:00
|
|
|
async function getConfig () {
|
|
|
|
config = await requestPVE(`/nodes/${node}/${type}/${vmid}/config`, "GET");
|
|
|
|
}
|
|
|
|
|
|
|
|
function populateResources () {
|
2022-12-21 23:10:13 +00:00
|
|
|
let name = type === "qemu" ? "name" : "hostname";
|
2023-04-06 19:47:40 +00:00
|
|
|
document.querySelector("#name").innerHTML = document.querySelector("#name").innerHTML.replace("%{vmname}", config.data[name]);
|
2023-05-15 21:22:12 +00:00
|
|
|
addResourceLine("resources", "images/resources/cpu.svg", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads");
|
|
|
|
addResourceLine("resources", "images/resources/ram.svg", "Memory", {type: "number", value: config.data.memory, min: 16, step: 1}, "MiB");
|
2023-01-16 23:05:58 +00:00
|
|
|
|
2022-12-21 23:39:09 +00:00
|
|
|
if (type === "lxc") {
|
2023-05-15 21:22:12 +00:00
|
|
|
addResourceLine("resources", "images/resources/swap.svg", "Swap", {type: "number", value: config.data.swap, min: 0, step: 1}, "MiB");
|
2023-01-10 00:02:25 +00:00
|
|
|
}
|
2023-01-11 10:43:56 +00:00
|
|
|
}
|
|
|
|
|
2023-01-09 04:26:20 +00:00
|
|
|
function addResourceLine (fieldset, iconHref, labelText, inputAttr, unitText=null) {
|
2022-12-21 08:49:57 +00:00
|
|
|
let field = document.querySelector(`#${fieldset}`);
|
2022-12-20 02:46:28 +00:00
|
|
|
|
2023-01-09 04:26:20 +00:00
|
|
|
let icon = document.createElement("img");
|
|
|
|
icon.src = iconHref;
|
2023-01-09 05:23:08 +00:00
|
|
|
icon.alt = labelText;
|
2023-01-09 04:26:20 +00:00
|
|
|
field.append(icon);
|
2022-12-21 23:56:52 +00:00
|
|
|
|
2022-12-20 01:59:34 +00:00
|
|
|
let label = document.createElement("label");
|
2023-05-03 21:06:27 +00:00
|
|
|
label.innerText = labelText;
|
2023-01-09 05:26:44 +00:00
|
|
|
label.htmlFor = labelText;
|
2022-12-21 08:49:57 +00:00
|
|
|
field.append(label);
|
2022-12-20 01:59:34 +00:00
|
|
|
|
|
|
|
let input = document.createElement("input");
|
2022-12-20 02:08:16 +00:00
|
|
|
for (let k in inputAttr) {
|
2022-12-20 02:12:39 +00:00
|
|
|
input.setAttribute(k, inputAttr[k])
|
2022-12-20 01:59:34 +00:00
|
|
|
}
|
2023-01-09 05:23:08 +00:00
|
|
|
input.id = labelText;
|
2023-02-23 21:11:43 +00:00
|
|
|
input.name = labelText;
|
|
|
|
input.required = true;
|
2023-04-12 22:47:05 +00:00
|
|
|
input.classList.add("w3-input");
|
|
|
|
input.classList.add("w3-border");
|
2022-12-21 08:49:57 +00:00
|
|
|
field.append(input);
|
|
|
|
|
2022-12-21 09:31:58 +00:00
|
|
|
if (unitText) {
|
|
|
|
let unit = document.createElement("p");
|
|
|
|
unit.innerText = unitText;
|
|
|
|
field.append(unit);
|
|
|
|
}
|
2023-01-09 04:26:20 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 19:55:17 +00:00
|
|
|
function populateDisk () {
|
2023-01-26 19:48:41 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
});
|
2023-05-15 21:22:12 +00:00
|
|
|
let ordered_keys = getOrdered(disks);
|
2023-01-26 19:48:41 +00:00
|
|
|
ordered_keys.forEach(element => {
|
|
|
|
let disk = disks[element];
|
|
|
|
addDiskLine("disks", prefix, busName, element, disk);
|
|
|
|
});
|
|
|
|
}
|
2023-02-14 21:03:53 +00:00
|
|
|
document.querySelector("#disk-add").addEventListener("click", handleDiskAdd);
|
2023-02-16 00:57:11 +00:00
|
|
|
|
|
|
|
if (type === "qemu") {
|
|
|
|
document.querySelector("#cd-add").classList.remove("none");
|
|
|
|
document.querySelector("#cd-add").addEventListener("click", handleCDAdd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-13 22:51:22 +00:00
|
|
|
function addDiskLine (fieldset, busPrefix, busName, device, diskDetails) {
|
2023-01-09 04:26:20 +00:00
|
|
|
let field = document.querySelector(`#${fieldset}`);
|
2023-02-13 22:51:22 +00:00
|
|
|
|
|
|
|
let diskName = `${busName} ${device}`;
|
|
|
|
let diskID = `${busPrefix}${device}`;
|
2023-01-17 17:52:20 +00:00
|
|
|
|
2023-01-18 23:43:57 +00:00
|
|
|
// Set the disk icon, either drive.svg or disk.svg
|
2023-01-09 04:26:20 +00:00
|
|
|
let icon = document.createElement("img");
|
2023-01-19 19:58:44 +00:00
|
|
|
icon.src = diskMetaData[type][busPrefix].icon;
|
2023-02-13 22:51:22 +00:00
|
|
|
icon.alt = diskName;
|
|
|
|
icon.dataset.disk = diskID;
|
2023-01-09 04:26:20 +00:00
|
|
|
field.append(icon);
|
|
|
|
|
2023-01-19 00:35:52 +00:00
|
|
|
// Add a label for the disk bus and device number
|
|
|
|
let diskLabel = document.createElement("label");
|
2023-05-03 21:06:27 +00:00
|
|
|
diskLabel.innerText = diskName;
|
2023-02-13 22:51:22 +00:00
|
|
|
diskLabel.dataset.disk = diskID;
|
2023-01-19 00:35:52 +00:00
|
|
|
field.append(diskLabel);
|
2023-01-18 23:43:57 +00:00
|
|
|
|
2023-01-19 00:35:52 +00:00
|
|
|
// Add text of the disk configuration
|
|
|
|
let diskDesc = document.createElement("p");
|
2023-02-13 22:51:22 +00:00
|
|
|
diskDesc.innerText = diskDetails;
|
|
|
|
diskDesc.dataset.disk = diskID;
|
2023-01-19 00:35:52 +00:00
|
|
|
field.append(diskDesc);
|
2023-01-16 23:45:51 +00:00
|
|
|
|
2023-01-19 00:35:52 +00:00
|
|
|
let actionDiv = document.createElement("div");
|
|
|
|
actionDiv.classList.add("last-item");
|
2023-01-19 19:58:44 +00:00
|
|
|
diskMetaData.actionBarOrder.forEach((element) => {
|
2023-01-19 02:13:07 +00:00
|
|
|
let action = document.createElement("img");
|
|
|
|
action.classList.add("clickable");
|
2023-02-10 21:36:47 +00:00
|
|
|
if (element === "detach_attach" && diskMetaData[type][busPrefix].actions.includes("attach")){ // attach
|
2023-02-21 21:50:54 +00:00
|
|
|
action.src = "images/actions/disk/attach.svg";
|
2023-01-19 02:13:07 +00:00
|
|
|
action.title = "Attach Disk";
|
2023-02-10 21:15:00 +00:00
|
|
|
action.addEventListener("click", handleDiskAttach);
|
2023-01-19 02:13:07 +00:00
|
|
|
}
|
2023-02-10 21:36:47 +00:00
|
|
|
else if (element === "detach_attach" && diskMetaData[type][busPrefix].actions.includes("detach")){ // detach
|
2023-02-21 21:50:54 +00:00
|
|
|
action.src = "images/actions/disk/detach.svg";
|
2023-01-19 02:13:07 +00:00
|
|
|
action.title = "Detach Disk";
|
2023-01-25 02:06:31 +00:00
|
|
|
action.addEventListener("click", handleDiskDetach);
|
2023-01-19 02:13:07 +00:00
|
|
|
}
|
2023-02-21 21:50:54 +00:00
|
|
|
else if (element === "delete") {
|
|
|
|
let active = diskMetaData[type][busPrefix].actions.includes(element) ? "active" : "inactive"; // resize
|
|
|
|
action.src = `images/actions/delete-${active}.svg`;
|
|
|
|
action.title = "Delete Disk";
|
2023-04-12 22:47:05 +00:00
|
|
|
if (active === "active") {
|
|
|
|
action.addEventListener("click", handleDiskDelete);
|
|
|
|
}
|
2023-02-21 21:50:54 +00:00
|
|
|
}
|
2023-01-19 02:13:07 +00:00
|
|
|
else {
|
2023-01-30 22:21:05 +00:00
|
|
|
let active = diskMetaData[type][busPrefix].actions.includes(element) ? "active" : "inactive"; // resize
|
2023-02-21 21:50:54 +00:00
|
|
|
action.src = `images/actions/disk/${element}-${active}.svg`;
|
2023-02-14 20:05:56 +00:00
|
|
|
if (active === "active") {
|
2023-04-03 21:17:18 +00:00
|
|
|
action.title = `${element.charAt(0).toUpperCase()}${element.slice(1)} Disk`;
|
2023-02-14 20:05:56 +00:00
|
|
|
if (element === "move") {
|
|
|
|
action.addEventListener("click", handleDiskMove);
|
|
|
|
}
|
|
|
|
else if (element === "resize") {
|
|
|
|
action.addEventListener("click", handleDiskResize);
|
|
|
|
}
|
2023-01-30 22:21:05 +00:00
|
|
|
}
|
2023-01-19 02:13:07 +00:00
|
|
|
}
|
2023-02-13 22:51:22 +00:00
|
|
|
action.dataset.disk = diskID;
|
2023-02-10 21:36:47 +00:00
|
|
|
action.alt = action.title;
|
2023-01-19 02:13:07 +00:00
|
|
|
actionDiv.append(action);
|
|
|
|
});
|
2023-01-19 00:35:52 +00:00
|
|
|
field.append(actionDiv);
|
2023-01-17 19:39:28 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 02:06:31 +00:00
|
|
|
async function handleDiskDetach () {
|
2023-05-05 21:43:15 +00:00
|
|
|
let header = `Detach ${this.dataset.disk}`;
|
|
|
|
let body = `<p>Are you sure you want to detach disk</p><p>${this.dataset.disk}</p>`;
|
|
|
|
dialog(header, body, async (result, form) => {
|
2023-02-10 21:15:00 +00:00
|
|
|
if (result === "confirm") {
|
2023-04-06 21:21:11 +00:00
|
|
|
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
|
2023-01-30 22:21:05 +00:00
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
2023-02-27 02:29:55 +00:00
|
|
|
disk: this.dataset.disk
|
2023-01-30 22:21:05 +00:00
|
|
|
};
|
2023-04-24 21:47:03 +00:00
|
|
|
let result = await requestAPI("/instance/disk/detach", "POST", body);
|
2023-01-30 22:21:05 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
}
|
2023-02-10 21:15:00 +00:00
|
|
|
else {
|
2023-05-12 21:26:26 +00:00
|
|
|
alert(result.error);
|
2023-02-28 23:56:39 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-02-10 21:15:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 21:43:15 +00:00
|
|
|
});
|
2023-02-10 21:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDiskAttach () {
|
2023-02-13 22:51:22 +00:00
|
|
|
let diskImage = config.data[this.dataset.disk];
|
2023-02-10 21:15:00 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
let header = `Attach ${diskImage}`;
|
|
|
|
let body = `<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"}" required></input>`;
|
2023-02-10 21:15:00 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
2023-02-10 21:15:00 +00:00
|
|
|
if (result === "confirm") {
|
2023-02-14 21:03:53 +00:00
|
|
|
let device = form.get("device");
|
2023-04-06 21:21:11 +00:00
|
|
|
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
|
2023-02-10 21:15:00 +00:00
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
2023-02-27 02:29:55 +00:00
|
|
|
disk: `${type === "qemu" ? "sata" : "mp"}${device}`,
|
|
|
|
data: type === "lxc" ? diskImage + `,mp=/mp${device}/` : diskImage
|
2023-02-10 21:15:00 +00:00
|
|
|
}
|
2023-04-24 21:47:03 +00:00
|
|
|
let result = await requestAPI("/instance/disk/attach", "POST", body);
|
2023-02-10 21:15:00 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
}
|
|
|
|
else {
|
2023-05-12 21:26:26 +00:00
|
|
|
alert(result.error);
|
2023-02-28 23:56:39 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-01-30 22:21:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 21:43:15 +00:00
|
|
|
});
|
2023-01-30 22:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDiskResize () {
|
2023-05-05 21:43:15 +00:00
|
|
|
let header = `Resize ${this.dataset.disk}`;
|
|
|
|
let body = `<label for="size-increment">Size Increment (GiB)</label><input class="w3-input w3-border" name="size-increment" id="size-increment" type="number" min="0" max="131072"></input>`;
|
2023-02-01 23:42:30 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
2023-02-10 21:15:00 +00:00
|
|
|
if (result === "confirm") {
|
2023-04-06 21:21:11 +00:00
|
|
|
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
|
2023-01-30 22:21:05 +00:00
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
2023-02-27 02:29:55 +00:00
|
|
|
disk: this.dataset.disk,
|
|
|
|
size: form.get("size-increment")
|
2023-01-30 22:21:05 +00:00
|
|
|
}
|
2023-04-24 21:47:03 +00:00
|
|
|
let result = await requestAPI("/instance/disk/resize", "POST", body);
|
2023-01-30 22:21:05 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
}
|
|
|
|
else{
|
2023-05-12 21:26:26 +00:00
|
|
|
alert(result.error);
|
2023-02-28 23:56:39 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-01-30 22:21:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 21:43:15 +00:00
|
|
|
});
|
2023-01-25 02:06:31 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 23:42:30 +00:00
|
|
|
async function handleDiskMove () {
|
2023-02-23 22:14:06 +00:00
|
|
|
let content = type === "qemu" ? "images" : "rootdir";
|
2023-05-11 07:13:41 +00:00
|
|
|
let storage = await requestPVE(`/nodes/${node}/storage`, "GET");
|
2023-02-02 00:12:36 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
let header = `Move ${this.dataset.disk}`;
|
2023-02-02 18:26:44 +00:00
|
|
|
|
2023-02-14 22:55:09 +00:00
|
|
|
let options = "";
|
2023-02-02 00:12:36 +00:00
|
|
|
storage.data.forEach((element) => {
|
2023-02-10 21:15:00 +00:00
|
|
|
if (element.content.includes(content)){
|
2023-02-14 22:55:09 +00:00
|
|
|
options += `<option value="${element.storage}">${element.storage}</option>"`;
|
2023-02-02 00:12:36 +00:00
|
|
|
}
|
|
|
|
});
|
2023-05-05 21:43:15 +00:00
|
|
|
let 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>`;
|
2023-02-02 00:12:36 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
let body = `
|
2023-02-14 22:55:09 +00:00
|
|
|
${select}
|
2023-04-12 22:47:05 +00:00
|
|
|
<label for="delete-check">Delete Source</label><input class="w3-input w3-border" name="delete-check" id="delete-check" type="checkbox" checked required>
|
2023-02-14 22:55:09 +00:00
|
|
|
`;
|
2023-02-02 19:35:14 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
2023-02-10 21:15:00 +00:00
|
|
|
if (result === "confirm") {
|
2023-04-06 21:21:11 +00:00
|
|
|
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
|
2023-02-02 18:26:44 +00:00
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
2023-02-27 02:29:55 +00:00
|
|
|
disk: this.dataset.disk,
|
|
|
|
storage: form.get("storage-select"),
|
|
|
|
delete: form.get("delete-check") === "on" ? "1": "0"
|
2023-02-02 18:26:44 +00:00
|
|
|
}
|
2023-04-24 21:47:03 +00:00
|
|
|
let result = await requestAPI("/instance/disk/move", "POST", body);
|
2023-02-02 18:26:44 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
}
|
2023-02-10 21:15:00 +00:00
|
|
|
else {
|
2023-05-12 21:26:26 +00:00
|
|
|
alert(result.error);
|
2023-02-28 23:56:39 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-02-02 18:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 21:43:15 +00:00
|
|
|
});
|
2023-02-01 23:42:30 +00:00
|
|
|
}
|
|
|
|
|
2023-02-10 21:36:47 +00:00
|
|
|
async function handleDiskDelete () {
|
2023-05-05 21:43:15 +00:00
|
|
|
let header = `Delete ${this.dataset.disk}`;
|
|
|
|
let body = `<p>Are you sure you want to <strong>delete</strong> disk</p><p>${this.dataset.disk}</p>`;
|
2023-02-10 21:36:47 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
2023-02-10 21:36:47 +00:00
|
|
|
if (result === "confirm") {
|
2023-04-06 21:21:11 +00:00
|
|
|
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
|
2023-02-10 21:36:47 +00:00
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
2023-02-27 02:29:55 +00:00
|
|
|
disk: this.dataset.disk
|
2023-02-10 21:36:47 +00:00
|
|
|
};
|
2023-04-24 21:47:03 +00:00
|
|
|
let result = await requestAPI("/instance/disk/delete", "POST", body);
|
2023-02-10 21:36:47 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
}
|
|
|
|
else {
|
2023-05-12 21:26:26 +00:00
|
|
|
alert(result.error);
|
2023-02-28 23:56:39 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-02-10 21:36:47 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 21:43:15 +00:00
|
|
|
});
|
2023-02-10 21:36:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 21:03:53 +00:00
|
|
|
async function handleDiskAdd () {
|
2023-02-23 22:14:06 +00:00
|
|
|
let content = type === "qemu" ? "images" : "rootdir";
|
2023-05-11 07:13:41 +00:00
|
|
|
let storage = await requestPVE(`/nodes/${node}/storage`, "GET");
|
2023-02-14 22:57:42 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
let header = "Create New Disk";
|
2023-02-14 21:56:27 +00:00
|
|
|
|
2023-02-14 22:55:09 +00:00
|
|
|
let options = "";
|
2023-02-14 21:56:27 +00:00
|
|
|
storage.data.forEach((element) => {
|
|
|
|
if (element.content.includes(content)){
|
2023-02-14 22:55:09 +00:00
|
|
|
options += `<option value="${element.storage}">${element.storage}</option>"`;
|
2023-02-14 21:56:27 +00:00
|
|
|
}
|
|
|
|
});
|
2023-05-05 21:43:15 +00:00
|
|
|
let 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>`;
|
2023-02-14 22:55:09 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
let body = `
|
2023-04-12 22:47:05 +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></input>
|
2023-02-14 22:55:09 +00:00
|
|
|
${select}
|
2023-04-12 22:47:05 +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></input>
|
2023-02-14 22:55:09 +00:00
|
|
|
`;
|
2023-02-14 21:56:27 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
dialog(header, body, async (result, form) => {
|
2023-02-15 00:17:35 +00:00
|
|
|
if (result === "confirm") {
|
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
2023-02-27 02:29:55 +00:00
|
|
|
disk: `${type === "qemu" ? "sata" : "mp"}${form.get("device")}`,
|
|
|
|
storage: form.get("storage-select"),
|
|
|
|
size: form.get("size")
|
2023-02-15 00:17:35 +00:00
|
|
|
};
|
2023-04-24 21:47:03 +00:00
|
|
|
let result = await requestAPI("/instance/disk/create", "POST", body);
|
2023-02-15 00:17:35 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
}
|
|
|
|
else {
|
2023-05-12 21:26:26 +00:00
|
|
|
alert(result.error);
|
2023-02-28 23:56:39 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-02-15 00:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 21:43:15 +00:00
|
|
|
});
|
2023-02-14 21:03:53 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 05:19:22 +00:00
|
|
|
async function handleCDAdd () {
|
|
|
|
let content = "iso";
|
2023-05-11 07:13:41 +00:00
|
|
|
let storage = await requestPVE(`/nodes/${node}/storage`, "GET");
|
2023-02-16 05:19:22 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
let header = `Add a CDROM`;
|
2023-02-16 05:19:22 +00:00
|
|
|
|
|
|
|
let storageOptions = "";
|
|
|
|
storage.data.forEach((element) => {
|
|
|
|
if (element.content.includes(content)){
|
|
|
|
storageOptions += `<option value="${element.storage}">${element.storage}</option>"`;
|
|
|
|
}
|
|
|
|
});
|
2023-05-05 21:43:15 +00:00
|
|
|
let storageSelect = `<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>${storageOptions}</select>`;
|
2023-02-16 05:19:22 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
let body = `
|
2023-04-12 22:47:05 +00:00
|
|
|
<label for="device">IDE</label><input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="3" required></input>
|
2023-02-16 05:19:22 +00:00
|
|
|
${storageSelect}
|
2023-04-19 21:11:35 +00:00
|
|
|
<label for="iso-select">Image</label><select class="w3-select w3-border" name="iso-select" id="iso-select" required></select>
|
2023-02-16 05:19:22 +00:00
|
|
|
`;
|
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
let d = dialog(header, body, async (result, form) => {
|
2023-02-16 05:19:22 +00:00
|
|
|
if (result === "confirm") {
|
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
2023-02-27 02:29:55 +00:00
|
|
|
disk: `ide${form.get("device")}`,
|
|
|
|
iso: form.get("iso-select")
|
2023-02-16 05:19:22 +00:00
|
|
|
};
|
2023-04-24 21:47:03 +00:00
|
|
|
let result = await requestAPI("/instance/disk/create", "POST", body);
|
2023-02-16 05:19:22 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
|
|
|
}
|
|
|
|
else {
|
2023-05-12 21:26:26 +00:00
|
|
|
alert(result.error);
|
2023-02-28 23:56:39 +00:00
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-02-16 05:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 21:43:15 +00:00
|
|
|
});
|
2023-02-16 05:19:22 +00:00
|
|
|
|
2023-05-05 21:43:15 +00:00
|
|
|
d.querySelector("#storage-select").addEventListener("change", async () => {
|
|
|
|
let storage = document.querySelector("#storage-select").value;
|
|
|
|
let ISOSelect = document.querySelector("#iso-select");
|
|
|
|
ISOSelect.innerHTML = `<option hidden disabled selected value></option>`;
|
|
|
|
let isos = await requestPVE(`/nodes/${node}/storage/${storage}/content`, "GET", {content: content});
|
|
|
|
isos.data.forEach((element) => {
|
|
|
|
if (element.content.includes(content)) {
|
|
|
|
ISOSelect.append(new Option(element.volid.replace(`${storage}:${content}/`, ""), element.volid));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-02-17 22:17:20 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 21:22:12 +00:00
|
|
|
function populateNetworks () {
|
|
|
|
document.querySelector("#networks").innerHTML = "";
|
|
|
|
let networks = {};
|
|
|
|
let prefix = networkMetaData.prefix;
|
|
|
|
Object.keys(config.data).forEach(element => {
|
|
|
|
if (element.startsWith(prefix)) {
|
|
|
|
networks[element.replace(prefix, "")] = config.data[element];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let ordered_keys = getOrdered(networks);
|
|
|
|
ordered_keys.forEach(element => {
|
2023-05-16 16:51:39 +00:00
|
|
|
addNetworkLine("networks", prefix, element, networks[element]);
|
2023-05-15 21:22:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-16 16:51:39 +00:00
|
|
|
function addNetworkLine (fieldset, prefix, netID, netDetails) {
|
2023-05-15 21:22:12 +00:00
|
|
|
let field = document.querySelector(`#${fieldset}`);
|
|
|
|
|
|
|
|
let icon = document.createElement("img");
|
|
|
|
icon.src = "images/resources/network.svg";
|
|
|
|
icon.alt = netID;
|
2023-05-16 16:51:39 +00:00
|
|
|
icon.dataset.network = `${prefix}${netID}`;
|
2023-05-15 22:41:54 +00:00
|
|
|
icon.dataset.netvals = netDetails;
|
2023-05-15 21:22:12 +00:00
|
|
|
field.appendChild(icon);
|
|
|
|
|
|
|
|
let netLabel = document.createElement("label");
|
|
|
|
netLabel.innerText = netID;
|
|
|
|
netLabel.dataset.network = netID;
|
2023-05-15 22:41:54 +00:00
|
|
|
netLabel.dataset.netvals = netDetails;
|
2023-05-15 21:22:12 +00:00
|
|
|
field.append(netLabel);
|
|
|
|
|
|
|
|
let netDesc = document.createElement("p");
|
|
|
|
netDesc.innerText = netDetails;
|
|
|
|
netDesc.dataset.network = netID;
|
2023-05-15 22:41:54 +00:00
|
|
|
netDesc.dataset.netvals = netDetails;
|
2023-05-15 21:22:12 +00:00
|
|
|
field.append(netDesc);
|
|
|
|
|
|
|
|
let actionDiv = document.createElement("div");
|
|
|
|
actionDiv.classList.add("last-item");
|
|
|
|
let action = document.createElement("img");
|
|
|
|
action.classList.add("clickable");
|
|
|
|
action.src = `images/actions/network/config.svg`;
|
|
|
|
action.title = "Config Network";
|
|
|
|
action.addEventListener("click", handleNetworkConfig);
|
|
|
|
action.dataset.network = netID;
|
2023-05-15 22:41:54 +00:00
|
|
|
action.dataset.netvals = netDetails;
|
2023-05-15 21:22:12 +00:00
|
|
|
actionDiv.appendChild(action);
|
|
|
|
field.append(actionDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleNetworkConfig () {
|
|
|
|
let netID = this.dataset.network;
|
2023-05-15 22:41:54 +00:00
|
|
|
let netDetails = this.dataset.netvals;
|
2023-05-15 21:22:12 +00:00
|
|
|
let header = `Edit ${netID}`;
|
2023-05-15 22:41:54 +00:00
|
|
|
let body = `<label for="rate">Rate Limit (MB/s)</label><input type="number" id="rate" name="rate" class="w3-input w3-border">`;
|
|
|
|
|
|
|
|
let d = dialog(header, body, async (result, form) => {
|
2023-05-15 21:22:12 +00:00
|
|
|
if (result === "confirm") {
|
2023-05-15 22:41:54 +00:00
|
|
|
document.querySelector(`img[data-network="${netID}"]`).src = "images/status/loading.svg";
|
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
|
|
|
netid: netID,
|
|
|
|
rate: form.get("rate")
|
|
|
|
}
|
|
|
|
let result = await requestAPI("/instance/network", "POST", body);
|
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateNetworks();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
alert(result.error);
|
|
|
|
await getConfig();
|
|
|
|
populateNetworks();
|
|
|
|
}
|
2023-05-15 21:22:12 +00:00
|
|
|
}
|
|
|
|
});
|
2023-05-15 22:41:54 +00:00
|
|
|
|
|
|
|
d.querySelector("#rate").value = netDetails.split("rate=")[1].split(",")[0];
|
2023-05-15 21:22:12 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 22:17:20 +00:00
|
|
|
async function handleFormExit () {
|
|
|
|
let body = {
|
|
|
|
node: node,
|
|
|
|
type: type,
|
|
|
|
vmid: vmid,
|
|
|
|
cores: document.querySelector("#Cores").value,
|
|
|
|
memory: document.querySelector("#Memory").value
|
|
|
|
}
|
2023-04-25 15:32:34 +00:00
|
|
|
let result = await requestAPI("/instance/resources", "POST", body);
|
2023-02-17 22:17:20 +00:00
|
|
|
if (result.status === 200) {
|
|
|
|
await getConfig();
|
|
|
|
populateDisk();
|
2023-05-15 22:41:54 +00:00
|
|
|
goToPage("index.html");
|
2023-02-17 22:17:20 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-05-12 21:26:26 +00:00
|
|
|
alert(result.error);
|
2023-02-17 22:17:20 +00:00
|
|
|
}
|
2023-02-16 05:19:22 +00:00
|
|
|
}
|