change /api/node/pci to /api/instance/pci

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-06-02 23:14:13 +00:00
parent 9dc751b5e4
commit 4f654f5dcf

78
main.js
View File

@ -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}`);
});