Skip to content

Commit

Permalink
feat(xo-server/xo-web/VM_coalesceLeaf): implement Coalesce Leaf (#7810)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuRA authored Jul 15, 2024
1 parent acffdbe commit 4a4122b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
28 changes: 28 additions & 0 deletions @xen-orchestra/xapi/vm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,33 @@ class Vm {
}
}

async coalesceLeaf($defer, vmRef) {
try {
await this.callAsync('VM.suspend', vmRef)
$defer(() => this.callAsync('VM.resume', vmRef, false, true))
} catch (error) {
if (error.code !== 'VM_BAD_POWER_STATE') {
throw error
}

const powerState = error.params[2].toLowerCase()
if (powerState !== 'halted' && powerState !== 'suspended') {
throw error
}
}

// plugin doc: https://docs.xenserver.com/en-us/xenserver/8/storage/manage.html#reclaim-space-by-using-the-offline-coalesce-tool
// result can be: `Success` or `VM has no leaf-coalesceable VDIs`
// https://github.com/xapi-project/sm/blob/eb292457c5fd5f00f6fc82454a915068ab15aa6f/drivers/coalesce-leaf#L48
const result = await this.callAsync('host.call_plugin', this.pool.master, 'coalesce-leaf', 'leaf-coalesce', {
vm_uuid: await this.getField('VM', vmRef, 'uuid'),
})

if (result.toLowerCase() !== 'success') {
throw new Error(result)
}
}

async snapshot(
$defer,
vmRef,
Expand Down Expand Up @@ -708,5 +735,6 @@ decorateClass(Vm, {
checkpoint: defer,
create: defer,
export: defer,
coalesceLeaf: defer,
snapshot: defer,
})
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [i18n] Add Persian translation (based on the contribution made by [@Jokar-xen](https://github.com/Jokar-xen)) (PR [#7775](https://github.com/vatesfr/xen-orchestra/pull/7775))
- [i18n] Improve Russian translation (Thanks [@TristisOris](https://github.com/TristisOris)!) (PR [#7807](https://github.com/vatesfr/xen-orchestra/pull/7807))
- [REST API] Expose XO6 dashboard informations at the `/rest/v0/dashboard` endpoint (PR [#7823](https://github.com/vatesfr/xen-orchestra/pull/7823))
- [VM/Advanced] Possibility to manually [_Coalesce Leaf_](https://docs.xenserver.com/en-us/xenserver/8/storage/manage.html#reclaim-space-by-using-the-offline-coalesce-tool) [#7757](https://github.com/vatesfr/xen-orchestra/issues/7757) (PR [#7810](https://github.com/vatesfr/xen-orchestra/pull/7810))

### Bug fixes

Expand All @@ -35,6 +36,7 @@
<!--packages-start-->

- @xen-orchestra/xapi minor
- xo-server minor
- xo-web minor

Expand Down
12 changes: 12 additions & 0 deletions packages/xo-server/src/api/vm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,3 +1826,15 @@ deleteVgpu.params = {
deleteVgpu.resolve = {
vgpu: ['vgpu', 'vgpu', ''],
}

// -------------------------------------------------------------------

export async function coalesceLeaf({ vm }) {
await this.getXapi(vm).VM_coalesceLeaf(vm._xapiRef)
}
coalesceLeaf.params = {
id: { type: 'string' },
}
coalesceLeaf.resolve = {
vm: ['id', 'VM', 'administrate'],
}
3 changes: 3 additions & 0 deletions packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,9 @@ const messages = {
'If the VTPM is in use, removing it will result in a dangerous data loss. Are you sure you want to remove the VTPM?',
infoUnknownPciOnNonRunningVm:
"When a VM is offline, it's not attached to any host, and therefore, it's impossible to determine the associated PCI devices, as it depends on the hardware environment in which it would be deployed.",
coalesceLeaf: 'Coalesce leaf',
coalesceLeafSuccess: 'Coalesce leaf success',
coalesceLeafSuspendVm: 'This will suspend the VM during the operation. Do you want to continue?',
poolAutoPoweronDisabled: 'Auto power on is disabled at pool level, click to fix automatically.',
vmRemoveButton: 'Remove',
vmConvertToTemplateButton: 'Convert to template',
Expand Down
12 changes: 12 additions & 0 deletions packages/xo-web/src/common/xo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,18 @@ export const deleteVms = async vms => {
}
}

export const coalesceLeafVm = async vm => {
if (vm.power_state !== 'Halted' && vm.power_state !== 'Suspended') {
await confirm({
title: _('coalesceLeaf'),
body: _('coalesceLeafSuspendVm'),
})
}
await _call('vm.coalesceLeaf', { id: resolveId(vm) })

success(_('coalesceLeaf'), _('coalesceLeafSuccess'))
}

export const importBackup = ({ remote, file, sr }) => _call('vm.importBackup', resolveIds({ remote, file, sr }))

export const importDeltaBackup = ({ remote, file, sr, mapVdisSrs }) =>
Expand Down
5 changes: 5 additions & 0 deletions packages/xo-web/src/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@
@extend .fa;
@extend .fa-fire;
}

&-coalesce-leaf {
@extend .fa;
@extend .fa-compress;
}
}

// Generic states
Expand Down
22 changes: 22 additions & 0 deletions packages/xo-web/src/xo-app/vm/tab-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
getVmsHaValues,
isPciPassthroughAvailable,
isVmRunning,
coalesceLeafVm,
pauseVm,
recoveryStartVm,
removeAcl,
Expand Down Expand Up @@ -698,6 +699,13 @@ export default class TabAdvanced extends Component {
icon='vm-suspend'
labelId='suspendVmLabel'
/>
<TabButton
btnStyle='primary'
handler={coalesceLeafVm}
handlerParam={vm}
icon='vm-coalesce-leaf'
labelId='coalesceLeaf'
/>
<TabButton
btnStyle='warning'
handler={forceReboot}
Expand Down Expand Up @@ -745,6 +753,13 @@ export default class TabAdvanced extends Component {
icon='vm-clone'
labelId='cloneVmLabel'
/>
<TabButton
btnStyle='primary'
handler={coalesceLeafVm}
handlerParam={vm}
icon='vm-coalesce-leaf'
labelId='coalesceLeaf'
/>
</span>
)}
{vm.power_state === 'Suspended' && (
Expand All @@ -756,6 +771,13 @@ export default class TabAdvanced extends Component {
icon='vm-start'
labelId='resumeVmLabel'
/>
<TabButton
btnStyle='primary'
handler={coalesceLeafVm}
handlerParam={vm}
icon='vm-coalesce-leaf'
labelId='coalesceLeaf'
/>
<TabButton
btnStyle='warning'
handler={forceShutdown}
Expand Down

0 comments on commit 4a4122b

Please sign in to comment.