From 2936d393688ab65cc70a585d238ac22571f97172 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 2 Jun 2023 23:14:13 +0000 Subject: [PATCH] change /api/node/pci to /api/instance/pci Signed-off-by: Arthur Lu --- main.js | 78 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/main.js b/main.js index bfb8d32..8db30a0 100644 --- a/main.js +++ b/main.js @@ -440,6 +440,45 @@ app.post("/api/instance/network", async (req, res) => { await handleResponse(req.body.node, result, res); }); +/** + * GET - get instance pcie device data + * request: + * - node: String - vm host node id + * - type: String - vm type (lxc, qemu) + * - vmid: Number - vm id number to destroy + * - hostpci: String - hostpci number + * responses: + * - 200: Object(pve_pci_device_object) + * - 401: {auth: false, path: String} + * - 500: {error: String} + */ +app.get("/api/instance/pci", async (req, res) => { + // check auth for specific instance + 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.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.query.hostpci}`].split(",")[0]; + console.log(device) + // get node's pci devices + 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; +}); + /** * POST - set basic resources for vm * request: @@ -604,45 +643,6 @@ app.delete("/api/instance", async (req, res) => { await handleResponse(req.body.node, result, res); }); -/** - * GET - get instance pcie device data - * request: - * - node: String - vm host node id - * - type: String - vm type (lxc, qemu) - * - vmid: Number - vm id number to destroy - * - hostpci: String - hostpci number - * responses: - * - 200: Object(pve_pci_device_object) - * - 401: {auth: false, path: String} - * - 500: {error: String} - */ -app.get("/api/nodes/pci", async (req, res) => { - // check auth for specific instance - 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.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.query.hostpci}`].split(",")[0]; - console.log(device) - // get node's pci devices - 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, () => { console.log(`proxmoxaas-api v${api.version} listening on port ${listenPort}`); }); \ No newline at end of file