Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(xo-server/resource-set): fix error when changing VM resource set #7144

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions packages/xo-server/src/api/vm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 8 additions & 0 deletions packages/xo-server/src/xo-mixins/resource-sets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down