check storage on disk create only when disk is not ide

This commit is contained in:
Arthur Lu 2023-06-23 03:37:15 +00:00
parent 4fa5fb158f
commit 8a8a4c0df6

View File

@ -409,6 +409,7 @@ app.delete("/api/instance/disk/delete", async (req, res) => {
* - disk: String - disk id (sata0, ide0) * - disk: String - disk id (sata0, ide0)
* - storage: String - storage to hold disk * - storage: String - storage to hold disk
* - size: Number - size of disk in GiB * - size: Number - size of disk in GiB
* - iso: String - file name to mount as cdrom
* responses: * responses:
* - 200: PVE Task Object * - 200: PVE Task Object
* - 401: {auth: false, path: String} * - 401: {auth: false, path: String}
@ -431,20 +432,21 @@ app.post("/api/instance/disk/create", async (req, res) => {
// setup request // setup request
let request = {}; let request = {};
if (!req.body.disk.includes("ide")) { if (!req.body.disk.includes("ide")) {
request[req.body.storage] = Number(req.body.size * 1024 ** 3); // setup request object // setup request
request[req.body.storage] = Number(req.body.size * 1024 ** 3);
// check request approval // check request approval
if (!await approveResources(req, req.cookies.username, request)) { if (!await approveResources(req, req.cookies.username, request)) {
res.status(500).send({ request: request, error: `Storage ${req.body.storage} could not fulfill request of size ${req.body.size}G.` }); res.status(500).send({ request: request, error: `Storage ${req.body.storage} could not fulfill request of size ${req.body.size}G.` });
res.end(); res.end();
return; return;
} }
} // target disk must be allowed according to storage options
// target disk must be allowed according to storage options let resourceConfig = db.getResourceConfig();
let resourceConfig = db.getResourceConfig(); if (!resourceConfig[req.body.storage].disks.some(diskPrefix => req.body.disk.startsWith(diskPrefix))) {
if (!resourceConfig[req.body.storage].disks.some(diskPrefix => req.body.disk.startsWith(diskPrefix))) { res.status(500).send({ error: `Requested target ${req.body.disk} is not in allowed list [${resourceConfig[req.body.storage].disks}].` });
res.status(500).send({ error: `Requested target ${req.body.disk} is not in allowed list [${resourceConfig[req.body.storage].disks}].` }); res.end();
res.end(); return;
return; }
} }
// setup action // setup action
let action = {}; let action = {};