chore(xo-server/rest-api): also pass xoObject to actions

This commit is contained in:
Julien Fontanet
2023-05-17 11:59:52 +02:00
parent 28b7e99ebc
commit 9cf8f8f492

View File

@@ -154,15 +154,15 @@ export default class RestApi {
collections.vms.actions = {
__proto__: null,
clean_reboot: vm => vm.$callAsync('clean_reboot').then(noop),
clean_shutdown: vm => vm.$callAsync('clean_shutdown').then(noop),
hard_reboot: vm => vm.$callAsync('hard_reboot').then(noop),
hard_shutdown: vm => vm.$callAsync('hard_shutdown').then(noop),
snapshot: async (vm, { name_label }) => {
clean_reboot: ({ xapiObject: vm }) => vm.$callAsync('clean_reboot').then(noop),
clean_shutdown: ({ xapiObject: vm }) => vm.$callAsync('clean_shutdown').then(noop),
hard_reboot: ({ xapiObject: vm }) => vm.$callAsync('hard_reboot').then(noop),
hard_shutdown: ({ xapiObject: vm }) => vm.$callAsync('hard_shutdown').then(noop),
snapshot: async ({ xapiObject: vm }, { name_label }) => {
const ref = await vm.$snapshot({ name_label })
return vm.$xapi.getField('VM', ref, 'uuid')
},
start: vm => vm.$callAsync('start', false, false).then(noop),
start: ({ xapiObject: vm }) => vm.$callAsync('start', false, false).then(noop),
}
api.param('collection', (req, res, next) => {
@@ -390,8 +390,9 @@ export default class RestApi {
return next()
}
const task = app.tasks.create({ name: `REST: ${action} ${req.collection.type}`, objectId: req.xoObject.id })
const pResult = task.run(() => fn(req.xapiObject, req.body))
const { xapiObject, xoObject } = req
const task = app.tasks.create({ name: `REST: ${action} ${req.collection.type}`, objectId: xoObject.id })
const pResult = task.run(() => fn({ xapiObject, xoObject }, req.body))
if (Object.hasOwn(req.query, 'sync')) {
pResult.then(result => res.json(result), next)
} else {