change /api/node/pci to /api/instance/pci
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
5eb5642166
commit
2936d39368
78
main.js
78
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}`);
|
||||
});
|
Loading…
Reference in New Issue
Block a user