forked from vatesfr/xen-orchestra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backups): add Healthcheck to continuous replication (vatesfr#6668)
- Loading branch information
1 parent
942b0f3
commit 3bbb828
Showing
4 changed files
with
44 additions
and
2 deletions.
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,50 @@ | ||
'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 baseVm = xapi.getObject(this._targetVmRef) ?? (await xapi.waitObject(this._targetVmRef)) | ||
const clonedRef = await xapi | ||
.callAsync('VM.clone', this._targetVmRef, `Health Check - ${baseVm.name_label}`) | ||
.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