simplify requestPVE args

This commit is contained in:
2023-09-12 19:16:19 +00:00
parent 8912ae5f3c
commit 40f36270aa
10 changed files with 66 additions and 60 deletions

View File

@@ -41,7 +41,7 @@ router.post("/:netid/create", async (req, res) => {
return;
}
// get current config
const currentConfig = await requestPVE(`/nodes/${params.node}/${params.type}/${params.vmid}/config`, "GET", null, null, pveAPIToken);
const currentConfig = await requestPVE(`/nodes/${params.node}/${params.type}/${params.vmid}/config`, "GET", { token: pveAPIToken });
// net interface must not exist
if (currentConfig.data.data[`net${params.netid}`]) {
res.status(500).send({ error: `Network interface net${params.netid} already exists.` });
@@ -74,7 +74,7 @@ router.post("/:netid/create", async (req, res) => {
action = JSON.stringify(action);
const method = params.type === "qemu" ? "POST" : "PUT";
// commit action
const result = await requestPVE(`${vmpath}/config`, method, req.cookies, action, pveAPIToken);
const result = await requestPVE(`${vmpath}/config`, method, { token: pveAPIToken }, action);
await handleResponse(params.node, result, res);
});
@@ -109,7 +109,7 @@ router.post("/:netid/modify", async (req, res) => {
return;
}
// get current config
const currentConfig = await requestPVE(`/nodes/${params.node}/${params.type}/${params.vmid}/config`, "GET", null, null, pveAPIToken);
const currentConfig = await requestPVE(`/nodes/${params.node}/${params.type}/${params.vmid}/config`, "GET", { token: pveAPIToken });
// net interface must already exist
if (!currentConfig.data.data[`net${params.netid}`]) {
res.status(500).send({ error: `Network interface net${params.netid} does not exist.` });
@@ -133,7 +133,7 @@ router.post("/:netid/modify", async (req, res) => {
action = JSON.stringify(action);
const method = params.type === "qemu" ? "POST" : "PUT";
// commit action
const result = await requestPVE(`${vmpath}/config`, method, req.cookies, action, pveAPIToken);
const result = await requestPVE(`${vmpath}/config`, method, { token: pveAPIToken }, action);
await handleResponse(params.node, result, res);
});
@@ -165,7 +165,7 @@ router.delete("/:netid/delete", async (req, res) => {
return;
}
// get current config
const currentConfig = await requestPVE(`/nodes/${params.node}/${params.type}/${params.vmid}/config`, "GET", null, null, pveAPIToken);
const currentConfig = await requestPVE(`/nodes/${params.node}/${params.type}/${params.vmid}/config`, "GET", { token: pveAPIToken });
// net interface must already exist
if (!currentConfig.data.data[`net${params.netid}`]) {
res.status(500).send({ error: `Network interface net${params.netid} does not exist.` });
@@ -176,6 +176,6 @@ router.delete("/:netid/delete", async (req, res) => {
const action = JSON.stringify({ delete: `net${params.netid}` });
const method = params.type === "qemu" ? "POST" : "PUT";
// commit action
const result = await requestPVE(`${vmpath}/config`, method, req.cookies, action, pveAPIToken);
const result = await requestPVE(`${vmpath}/config`, method, { token: pveAPIToken }, action);
await handleResponse(params.node, result, res);
});