From 2b973275c0ef71c6bd78ed2e1a33d12248ba54c7 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Fri, 8 Dec 2023 15:17:51 +0100 Subject: [PATCH] feat(xo-server/rest-api): expose metadata & mirror backup jobs --- CHANGELOG.unreleased.md | 3 ++ packages/xo-server/src/xo-mixins/rest-api.mjs | 49 +++++++++++++++---- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 9265cb186..fe9a164a0 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -9,6 +9,9 @@ - [Forget SR] Changed the modal message and added a confirmation text to be sure the action is understood by the user [#7148](https://github.com/vatesfr/xen-orchestra/issues/7148) (PR [#7155](https://github.com/vatesfr/xen-orchestra/pull/7155)) - [REST API] `/backups` has been renamed to `/backup` (redirections are in place for compatibility) +- [REST API] _VM backup & Replication_ jobs have been moved from `/backup/jobs/:id` to `/backup/jobs/vm/:id` (redirections are in place for compatibility) +- [REST API] _XO config & Pool metadata Backup_ jobs are available at `/backup/jobs/metadata` +- [REST API] _Mirror Backup_ jobs are available at `/backup/jobs/metadata` ### Bug fixes diff --git a/packages/xo-server/src/xo-mixins/rest-api.mjs b/packages/xo-server/src/xo-mixins/rest-api.mjs index b86be07a9..d38e659c2 100644 --- a/packages/xo-server/src/xo-mixins/rest-api.mjs +++ b/packages/xo-server/src/xo-mixins/rest-api.mjs @@ -285,21 +285,19 @@ export default class RestApi { res.redirect(308, req.baseUrl + '/backup' + req.params[0]) }) + const backupTypes = { + __proto__: null, + + metadata: 'metadataBackup', + mirror: 'mirrorBackup', + vm: 'backup', + } + api .get( '/backup', wrap((req, res) => sendObjects([{ id: 'jobs' }, { id: 'logs' }], req, res)) ) - .get( - '/backup/jobs', - wrap(async (req, res) => sendObjects(await app.getAllJobs('backup'), req, res)) - ) - .get( - '/backup/jobs/:id', - wrap(async (req, res) => { - res.json(await app.getJob(req.params.id, 'backup')) - }) - ) .get( '/backup/logs', wrap(async (req, res) => { @@ -311,6 +309,37 @@ export default class RestApi { await sendObjects(logs, req, res) }) ) + .get( + '/backup/jobs', + wrap((req, res) => + sendObjects( + Object.keys(backupTypes).map(id => ({ id })), + req, + res + ) + ) + ) + + for (const [collection, type] of Object.entries(backupTypes)) { + api + .get( + '/backup/jobs/' + collection, + wrap(async (req, res) => sendObjects(await app.getAllJobs(type), req, res)) + ) + .get( + `/backup/jobs/${collection}/:id`, + wrap(async (req, res) => { + res.json(await app.getJob(req.params.id, type)) + }) + ) + } + + // For compatibility, redirect /backup/jobs/:id to /backup/jobs/vm/:id + api.get('/backup/jobs/:id', (req, res) => { + res.redirect(308, req.baseUrl + '/backup/jobs/vm/' + req.params.id) + }) + + api .get( '/restore', wrap((req, res) => sendObjects([{ id: 'logs' }], req, res))