feat(xo-server/backups-ng): ability to restore a VM via proxy (#4821)

See #4814
This commit is contained in:
badrAZ 2020-02-26 13:58:17 +01:00 committed by GitHub
parent 7abc833ebe
commit c55ed42b2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -841,7 +841,36 @@ export default class BackupNg {
// └─ task.end
async importVmBackupNg(id: string, srId: string): Promise<string> {
const app = this._app
const xapi = app.getXapi(srId)
const sr = xapi.getObject(srId)
const { metadataFilename, remoteId } = parseVmBackupId(id)
const { proxy, url, options } = await app.getRemoteWithCredentials(remoteId)
if (proxy !== undefined) {
const {
allowUnauthorized,
host,
password,
username,
} = await app.getXenServer(app.getXenServerIdByObject(sr.$id))
return app.callProxyMethod(proxy, 'backup.importVmBackup', {
backupId: metadataFilename,
remote: {
url,
options,
},
srUuid: sr.uuid,
xapi: {
allowUnauthorized,
credentials: {
username,
password,
},
url: host,
},
})
}
const handler = await app.getRemoteHandler(remoteId)
const metadata: Metadata = JSON.parse(
String(await handler.readFile(metadataFilename))
@ -852,7 +881,6 @@ export default class BackupNg {
throw new Error(`no importer for backup mode ${metadata.mode}`)
}
const xapi = app.getXapi(srId)
const { jobId, timestamp: time } = metadata
const logger = this._logger
return wrapTaskFn(
@ -872,7 +900,7 @@ export default class BackupNg {
metadataFilename,
metadata,
xapi,
xapi.getObject(srId),
sr,
taskId,
logger
)::pFinally(() => {