Compare commits

...

1 Commits

Author SHA1 Message Date
Julien Fontanet
cf5b1225f0 feat(xo-server/rest-api): expose /vms/:id/vdis
But we are loosing VBDs info which is not ideal.
2024-02-20 10:18:44 +01:00

View File

@@ -72,8 +72,11 @@ async function* makeObjectsStream(iterable, makeResult, json) {
async function sendObjects(iterable, req, res, path = req.path) {
const { query } = req
const basePath = join(req.baseUrl, path)
const makeUrl = ({ id }) => join(basePath, typeof id === 'number' ? String(id) : id)
const { baseUrl } = req
const makeUrl = item => {
const { id } = item
return join(baseUrl, typeof path === 'function' ? path(item) : path, typeof id === 'number' ? String(id) : id)
}
let makeResult
let { fields } = query
@@ -277,6 +280,36 @@ export default class RestApi {
},
}
{
async function vdis(req, res) {
const { object, query } = req
const vdiIds = new Set()
for (const vbdId of object.$VBDs) {
const vbd = app.getObject(vbdId, 'VBD')
const vdiId = vbd.VDI
if (vdiId !== undefined) {
vdiIds.add(vdiId)
}
}
await sendObjects(
handleArray(
Array.from(vdiIds, id => app.getObject(id, ['VDI', 'VDI-snapshot'])),
query.filter,
ifDef(query.limit, Number)
),
req,
res,
({ type }) => type.toLowerCase() + 's'
)
}
for (const collection of ['vms', 'vm-snapshots', 'vm-templates']) {
collections[collection].routes.vdis = vdis
}
}
collections.pools.actions = {
create_vm: withParams(
defer(async ($defer, { xapiObject: { $xapi } }, { affinity, boot, install, template, ...params }, req) => {