diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 2f5c2ee30b3..c11f2260923 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -16,6 +16,7 @@ - [Backup/Restore] In case of snapshot with memory, create the suspend VDI on the correct SR instead of the default one - [Import/ESXi] Handle `Cannot read properties of undefined (reading 'perDatastoreUsage')` error when importing VM without storage (PR [#7168](https://github.com/vatesfr/xen-orchestra/pull/7168)) - [Export/OVA] Handle export with resulting disk larger than 8.2GB (PR [#7183](https://github.com/vatesfr/xen-orchestra/pull/7183)) +- [Self Service] Fix error displayed after adding a VM to a resource set (PR [#7144](https://github.com/vatesfr/xen-orchestra/pull/7144)) ### Packages to release @@ -37,6 +38,7 @@ - @xen-orchestra/backups patch - @xen-orchestra/cr-seed-cli major - @xen-orchestra/vmware-explorer patch +- xo-server patch - xo-server-netbox minor - xo-vmdk-to-vhd patch - xo-web patch diff --git a/packages/xo-server/src/api/vm.mjs b/packages/xo-server/src/api/vm.mjs index 0929e71a1d9..202183017cd 100644 --- a/packages/xo-server/src/api/vm.mjs +++ b/packages/xo-server/src/api/vm.mjs @@ -647,11 +647,12 @@ export const set = defer(async function ($defer, params) { } await this.setVmResourceSet(vmId, resourceSetId, true) - } - - const share = extract(params, 'share') - if (share) { - await this.shareVmResourceSet(vmId) + } else { + // share is implicit in the other branch with `setVmResourceSet` + const share = extract(params, 'share') + if (share) { + await this.shareVmResourceSet(vmId) + } } const suspendSr = extract(params, 'suspendSr') diff --git a/packages/xo-server/src/xo-mixins/resource-sets.mjs b/packages/xo-server/src/xo-mixins/resource-sets.mjs index 303eb7c9b8b..2a651bb22ee 100644 --- a/packages/xo-server/src/xo-mixins/resource-sets.mjs +++ b/packages/xo-server/src/xo-mixins/resource-sets.mjs @@ -408,6 +408,11 @@ export default class { await Promise.all(mapToArray(sets, set => this._save(set))) } + /** + * Change or remove (if null) the resource set a VM belongs to + * + * The VM is also automatically shared in the new resource set. + */ @decorateWith(deferrable) async setVmResourceSet($defer, vmId, resourceSetId, force = false) { const xapi = this._app.getXapi(vmId) @@ -438,6 +443,9 @@ export default class { await this._app.removeAclsForObject(vmId) } if (resourceSetId != null) { + // ensure the object VM is up-to-date + await xapi.barrier(xapi.getObject(vmId).$ref) + await this.shareVmResourceSet(vmId) } }