fix nodes pci endpoint
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
15f4026979
commit
5eb5642166
21
main.js
21
main.js
@ -618,20 +618,29 @@ app.delete("/api/instance", async (req, res) => {
|
||||
*/
|
||||
app.get("/api/nodes/pci", async (req, res) => {
|
||||
// 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);
|
||||
if (!auth) { return; }
|
||||
// check device is in instance config
|
||||
let config = (await requestPVE(`${vmpath}/config`, "GET", req.cookies)).data.data;
|
||||
if (!config[`hostpci${req.body.hostpci}`]) {
|
||||
res.status(500).send({ error: `Could not find hostpci${req.body.hostpci} in ${req.body.vmid}.` });
|
||||
if (!config[`hostpci${req.query.hostpci}`]) {
|
||||
res.status(500).send({ error: `Could not find hostpci${req.query.hostpci} in ${req.query.vmid}.` });
|
||||
res.end();
|
||||
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
|
||||
let result = (await requestPVE(`/nodes/${req.body.node}/hardware/pci/${device}`, "GET", req.cookies)).data.data;
|
||||
return result;
|
||||
let result = (await requestPVE(`/nodes/${req.query.node}/hardware/pci`, "GET", req.cookies, null, pveAPIToken)).data.data;
|
||||
let deviceData = [];
|
||||
result.forEach((element) => {
|
||||
if (element.id.startsWith(device)) {
|
||||
deviceData.push(element);
|
||||
}
|
||||
});
|
||||
res.status(200).send(deviceData);
|
||||
res.end();
|
||||
return;
|
||||
});
|
||||
|
||||
app.listen(listenPort, () => {
|
||||
|
2
pve.js
2
pve.js
@ -35,7 +35,7 @@ export async function requestPVE(path, method, cookies, body = null, token = nul
|
||||
|
||||
export async function handleResponse(node, result, res) {
|
||||
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;
|
||||
while (true) {
|
||||
let taskStatus = await requestPVE(`/nodes/${node}/tasks/${upid}/status`, "GET", null, null, pveAPIToken);
|
||||
|
Loading…
Reference in New Issue
Block a user