fix nodes pci endpoint

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-06-01 17:12:52 +00:00
parent 2dec550425
commit 9dc751b5e4
2 changed files with 16 additions and 7 deletions

21
main.js
View File

@ -618,20 +618,29 @@ app.delete("/api/instance", async (req, res) => {
*/ */
app.get("/api/nodes/pci", async (req, res) => { app.get("/api/nodes/pci", async (req, res) => {
// check auth for specific instance // check auth for specific instance
let vmpath = `/nodes/${req.body.node}/${req.body.type}/${req.body.vmid}`; let vmpath = `/nodes/${req.query.node}/${req.query.type}/${req.query.vmid}`;
let auth = await checkAuth(req.cookies, res, vmpath); let auth = await checkAuth(req.cookies, res, vmpath);
if (!auth) { return; } if (!auth) { return; }
// check device is in instance config // check device is in instance config
let config = (await requestPVE(`${vmpath}/config`, "GET", req.cookies)).data.data; let config = (await requestPVE(`${vmpath}/config`, "GET", req.cookies)).data.data;
if (!config[`hostpci${req.body.hostpci}`]) { if (!config[`hostpci${req.query.hostpci}`]) {
res.status(500).send({ error: `Could not find hostpci${req.body.hostpci} in ${req.body.vmid}.` }); res.status(500).send({ error: `Could not find hostpci${req.query.hostpci} in ${req.query.vmid}.` });
res.end(); res.end();
return; return;
} }
let device = config[`hostpci${req.body.hostpci}`]; let device = config[`hostpci${req.query.hostpci}`].split(",")[0];
console.log(device)
// get node's pci devices // get node's pci devices
let result = (await requestPVE(`/nodes/${req.body.node}/hardware/pci/${device}`, "GET", req.cookies)).data.data; let result = (await requestPVE(`/nodes/${req.query.node}/hardware/pci`, "GET", req.cookies, null, pveAPIToken)).data.data;
return result; let deviceData = [];
result.forEach((element) => {
if (element.id.startsWith(device)) {
deviceData.push(element);
}
});
res.status(200).send(deviceData);
res.end();
return;
}); });
app.listen(listenPort, () => { app.listen(listenPort, () => {

2
pve.js
View File

@ -35,7 +35,7 @@ export async function requestPVE(path, method, cookies, body = null, token = nul
export async function handleResponse(node, result, res) { export async function handleResponse(node, result, res) {
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay)); const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
if (result.data.data) { if (result.data.data && typeof(result.data.data) === String && result.data.data.startsWith("UPID:")) {
let upid = result.data.data; let upid = result.data.data;
while (true) { while (true) {
let taskStatus = await requestPVE(`/nodes/${node}/tasks/${upid}/status`, "GET", null, null, pveAPIToken); let taskStatus = await requestPVE(`/nodes/${node}/tasks/${upid}/status`, "GET", null, null, pveAPIToken);