Compare commits

...

1 Commits

Author SHA1 Message Date
Julien Fontanet
433d2fb6c4 WiP 2024-09-02 13:35:04 +02:00
2 changed files with 33 additions and 13 deletions

View File

@@ -200,6 +200,18 @@ class Vm {
}
}
_safeSetIsATemplate(ref) {
return pCatch.call(
this.setField('VM', ref, 'is_a_template', false),
// Ignore if this fails due to license restriction
//
// see https://bugs.xenserver.org/browse/XSO-766
{ code: 'LICENSE_RESTRICTION' },
noop
)
}
async assertHealthyVdiChains(vmRef, tolerance = this._maxUncoalescedVdis) {
const vdiRefs = {}
;(await this.getRecords('VBD', await this.getField('VM', vmRef, 'VBDs'))).forEach(({ VDI: ref }) => {
@@ -486,9 +498,10 @@ class Vm {
if (useSnapshot === undefined) {
useSnapshot = isVmRunning(vm)
}
let exportedVmRef, destroySnapshot
let exportedVmRef, destroySnapshot, isSnapshot
if (useSnapshot) {
exportedVmRef = await this.VM_snapshot(vmRef, { cancelToken, name_label: `[XO Export] ${vm.name_label}` })
isSnapshot = true
destroySnapshot = () =>
this.VM_destroy(exportedVmRef).catch(error => {
warn('VM_export: failed to destroy snapshot', {
@@ -500,8 +513,13 @@ class Vm {
$defer.onFailure(destroySnapshot)
} else {
exportedVmRef = vmRef
isSnapshot = vm.is_a_snapshot
}
try {
// VM snapshots are marked as templates, unfortunately it does not play well with XVA export/import
// which will import them as templates and not VM snapshots or plain VMs
await this._safeSetIsATemplate(exportedVmRef, false)
const response = await this.getResource(cancelToken, '/export/', {
query: {
ref: exportedVmRef,
@@ -510,6 +528,16 @@ class Vm {
task: taskRef,
})
if (isSnapshot) {
// FIXME: VM_IS_SNAPSHOT(OpaqueRef:757d6cfd-a185-4114-bfc8-fb9fdd279bf2, make_into_template)
this._safeSetIsATemplate(exportedVmRef, true).catch(error => {
warn('VM_export: failed to reset is_a_template on snapshot', {
error,
snapshotRef: exportedVmRef,
vmRef,
})
})
}
if (useSnapshot) {
finished(response.body, destroySnapshot)
}
@@ -692,18 +720,6 @@ class Vm {
// detached async
this._httpHook(vm, '/post-sync').catch(noop)
// VM snapshots are marked as templates, unfortunately it does not play well with XVA export/import
// which will import them as templates and not VM snapshots or plain VMs
await pCatch.call(
this.setField('VM', ref, 'is_a_template', false),
// Ignore if this fails due to license restriction
//
// see https://bugs.xenserver.org/browse/XSO-766
{ code: 'LICENSE_RESTRICTION' },
noop
)
if (destroyNobakVdis) {
// destroy the ignored VBDs on the VM snapshot
const ignoredSnapshotVbds = await listTaggedVdiVbds(this, await this.getField('VM', ref, 'VBDs'), ignoredVdisTag)

View File

@@ -15,6 +15,8 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- VMs snapshotted with XO will no longer appear as regular VMs in other clients like `xe`
### Packages to release
> When modifying a package, add it here with its release type.
@@ -31,4 +33,6 @@
<!--packages-start-->
- @xen-orchestra/xapi patch
<!--packages-end-->