-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@xen-orchestra/backups): add Healthcheck to continuous replication
- Loading branch information
1 parent
5419957
commit 849beef
Showing
4 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,47 @@ | ||
'use strict' | ||
|
||
const { Task } = require('../Task') | ||
const assert = require('node:assert/strict') | ||
const { HealthCheckVmBackup } = require('../HealthCheckVmBackup') | ||
|
||
function extractOpaqueRef(str) { | ||
const OPAQUE_REF_RE = /OpaqueRef:[0-9a-z-]+/ | ||
const matches = OPAQUE_REF_RE.exec(str) | ||
if (!matches) { | ||
throw new Error('no opaque ref found') | ||
} | ||
return matches[0] | ||
} | ||
exports.MixinReplicationWriter = (BaseClass = Object) => | ||
class MixinReplicationWriter extends BaseClass { | ||
constructor({ sr, ...rest }) { | ||
super(rest) | ||
|
||
this._sr = sr | ||
} | ||
|
||
healthCheck(sr) { | ||
assert.notEqual(this._targetVmRef, undefined, 'A vm should have been transfered to be health checked') | ||
// copy VM | ||
return Task.run( | ||
{ | ||
name: 'health check', | ||
}, | ||
async () => { | ||
const { $xapi: xapi } = sr | ||
let clonedVm | ||
try { | ||
const clonedRef = await xapi.callAsync('VM.clone', this._targetVmRef, 'cloning').then(extractOpaqueRef) | ||
clonedVm = xapi.getObject(clonedRef) ?? (await xapi.waitObject(clonedRef)) | ||
|
||
await new HealthCheckVmBackup({ | ||
restoredVm: clonedVm, | ||
xapi, | ||
}).run() | ||
} finally { | ||
clonedVm && (await xapi.VM_destroy(clonedVm.$ref)) | ||
} | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters