feat(xo-server/self): can ignore VM snapshots resources usage (#5164)

See xoa-support#2643

With the config option `selfService.ignoreVmSnapshotResources`
This commit is contained in:
Pierre Donias 2020-07-27 16:08:20 +02:00 committed by GitHub
parent 9b6e4c605b
commit d3a88011a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 7 deletions

View File

@ -11,6 +11,7 @@
- [VM/disks] By default, sort disks by their device position instead of their name [#5163](https://github.com/vatesfr/xen-orchestra/issues/5163) (PR [#5165](https://github.com/vatesfr/xen-orchestra/pull/5165))
- [Schedule/edit] Ability to enable/disable an ordinary job's schedule [#5026](https://github.com/vatesfr/xen-orchestra/issues/5026) (PR [#5111](https://github.com/vatesfr/xen-orchestra/pull/5111))
- [New schedule] Enable 'Enable immediately after creation' by default (PR [#5111](https://github.com/vatesfr/xen-orchestra/pull/5111))
- [Self Service] Ability to globally ignore snapshots in resource set quotas (PR [#5164](https://github.com/vatesfr/xen-orchestra/pull/5164))
### Bug fixes
@ -37,5 +38,5 @@
> In case of conflict, the highest (lowest in previous list) `$version` wins.
- xo-vmdk-to-vhd patch
- xo-server patch
- xo-server minor
- xo-web minor

View File

@ -237,7 +237,11 @@ Then, you can define quotas on this set:
- max disk usage
:::tip
Snapshotting a VM within a self-service will _not_ use the quota from the resource set. The same rule applies for backups and replication.
Replicated VMs and snapshots created by a backup job don't use quotas.
:::
:::tip
A snapshot of a Self Service VM will use as much resources as a VM would. You can disable this by setting `ignoreVmSnapshotResources` to `true` in the `selfService` section of `xo-server`'s config.
:::
When you click on create, you can see the resource set and remove or edit it:

View File

@ -119,6 +119,12 @@ timeout = 600e3
#[workerOptions]
#numWorkers = 2
[selfService]
# If true, a snapshot of a Self Service VM will consume as much resources as a
# normal VM would
ignoreVmSnapshotResources = false
[xapiOptions]
maxUncoalescedVdis = 1
vdiExportConcurrency = 12

View File

@ -824,7 +824,8 @@ export const snapshot = defer(async function (
}
if (vm.resourceSet !== undefined) {
const usage = await this.computeVmResourcesUsage(vm)
// Compute the resource usage of the VM as if it was used by the snapshot
const usage = await this.computeVmSnapshotResourcesUsage(vm)
await this.allocateLimitsInResourceSet(
usage,
vm.resourceSet,
@ -1234,6 +1235,8 @@ export const revert = defer(async function ($defer, { snapshot }) {
)
)
// Compute the resource usage of the snapshot that's being reverted as if it
// was used by the VM
const snapshotUsage = await this.computeVmResourcesUsage(snapshot)
await this.allocateLimitsInResourceSet(
snapshotUsage,

View File

@ -134,6 +134,19 @@ export default class {
)
}
async computeVmSnapshotResourcesUsage(snapshot) {
if (this._xo._config.selfService?.ignoreVmSnapshotResources) {
return {}
}
return this.computeVmResourcesUsage(snapshot)
}
computeResourcesUsage(vm) {
return vm.type === 'VM-snapshot'
? this.computeVmSnapshotResourcesUsage(vm)
: this.computeVmResourcesUsage(vm)
}
async createResourceSet(
name,
subjects = undefined,
@ -381,9 +394,7 @@ export default class {
const { limits } = set
forEach(
await this.computeVmResourcesUsage(
this._xo.getObject(object.$id)
),
await this.computeResourcesUsage(this._xo.getObject(object.$id)),
(usage, resource) => {
const limit = limits[resource]
if (limit) {
@ -411,7 +422,7 @@ export default class {
return
}
const resourcesUsage = await this.computeVmResourcesUsage(
const resourcesUsage = await this.computeResourcesUsage(
this._xo.getObject(vmId)
)