improve getUsedResources,
remove unused params for some pve functions
This commit is contained in:
@@ -94,7 +94,7 @@ router.post("/:disk/attach", async (req, res) => {
|
||||
return;
|
||||
}
|
||||
// target disk must be allowed according to source disk's storage options
|
||||
const diskConfig = await getDiskInfo(params.node, params.type, params.vmid, `unused${params.source}`); // get target disk
|
||||
const diskConfig = await getDiskInfo(params.node, config, `unused${params.source}`); // get target disk
|
||||
const resourceConfig = db.getGlobalConfig().resources;
|
||||
if (!resourceConfig[diskConfig.storage].disks.some(diskPrefix => params.disk.startsWith(diskPrefix))) {
|
||||
res.status(500).send({ error: `Requested target ${params.disk} is not in allowed list [${resourceConfig[diskConfig.storage].disks}].` });
|
||||
@@ -141,8 +141,10 @@ router.post("/:disk/resize", async (req, res) => {
|
||||
if (!auth) {
|
||||
return;
|
||||
}
|
||||
// get current config
|
||||
const config = (await requestPVE(`${vmpath}/config`, "GET", { cookies: req.cookies })).data.data;
|
||||
// check disk existence
|
||||
const diskConfig = await getDiskInfo(params.node, params.type, params.vmid, params.disk); // get target disk
|
||||
const diskConfig = await getDiskInfo(params.node, config, params.disk); // get target disk
|
||||
if (!diskConfig) { // exit if disk does not exist
|
||||
res.status(500).send({ error: `requested disk ${params.disk} does not exist.` });
|
||||
res.end();
|
||||
@@ -196,8 +198,10 @@ router.post("/:disk/move", async (req, res) => {
|
||||
if (!auth) {
|
||||
return;
|
||||
}
|
||||
// get current config
|
||||
const config = (await requestPVE(`${vmpath}/config`, "GET", { cookies: req.cookies })).data.data;
|
||||
// check disk existence
|
||||
const diskConfig = await getDiskInfo(params.node, params.type, params.vmid, params.disk); // get target disk
|
||||
const diskConfig = await getDiskInfo(params.node, config, params.disk); // get target disk
|
||||
if (!diskConfig) { // exit if disk does not exist
|
||||
res.status(500).send({ error: `requested disk ${params.disk} does not exist.` });
|
||||
res.end();
|
||||
|
@@ -45,7 +45,7 @@ router.get("/:hostpci", async (req, res) => {
|
||||
}
|
||||
const device = config[`hostpci${params.hostpci}`].split(",")[0];
|
||||
// get node's pci devices
|
||||
const deviceData = await getDeviceInfo(params.node, params.type, params.vmid, device);
|
||||
const deviceData = await getDeviceInfo(params.node, device);
|
||||
if (!deviceData) {
|
||||
res.status(500).send({ error: `Could not find hostpci${params.hostpci}=${device} in ${params.node}.` });
|
||||
res.end();
|
||||
@@ -96,7 +96,7 @@ router.post("/:hostpci/modify", async (req, res) => {
|
||||
params.device = params.device.split(".")[0];
|
||||
// get instance config to check if device has not changed
|
||||
const config = (await requestPVE(`/nodes/${params.node}/${params.type}/${params.vmid}/config`, "GET", { token: pveAPIToken })).data.data;
|
||||
const currentDeviceData = await getDeviceInfo(params.node, params.type, params.vmid, config[`hostpci${params.hostpci}`].split(",")[0]);
|
||||
const currentDeviceData = await getDeviceInfo(params.node, config[`hostpci${params.hostpci}`].split(",")[0]);
|
||||
if (!currentDeviceData) {
|
||||
res.status(500).send({ error: `No device in hostpci${params.hostpci}.` });
|
||||
res.end();
|
||||
@@ -105,7 +105,7 @@ router.post("/:hostpci/modify", async (req, res) => {
|
||||
// only check user and node availability if base id is different
|
||||
if (currentDeviceData.id.split(".")[0] !== params.device) {
|
||||
// setup request
|
||||
const deviceData = await getDeviceInfo(params.node, params.type, params.vmid, params.device);
|
||||
const deviceData = await getDeviceInfo(params.node, params.device);
|
||||
const request = { pci: deviceData.device_name };
|
||||
// check resource approval
|
||||
if (!await approveResources(req, req.cookies.username, request)) {
|
||||
@@ -184,7 +184,7 @@ router.post("/create", async (req, res) => {
|
||||
hostpci++;
|
||||
}
|
||||
// setup request
|
||||
const deviceData = await getDeviceInfo(params.node, params.type, params.vmid, params.device);
|
||||
const deviceData = await getDeviceInfo(params.node, params.device);
|
||||
const request = {
|
||||
pci: deviceData.device_name
|
||||
};
|
||||
|
Reference in New Issue
Block a user