Skip to content

Commit

Permalink
feat(xo-web): ability to block/unblock migration
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-m-dev committed Nov 13, 2024
1 parent 05c4e8e commit 330965a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Ignore leading and trailing spaces when editing VM/Pools/Hosts/SRs names and descriptions (PR [#8115](https://github.com/vatesfr/xen-orchestra/pull/8115))
- [VM/Advanced] in Nested virtualization section, add warning tooltip and link to documentation (PR [#8107](https://github.com/vatesfr/xen-orchestra/pull/8107))
- [VM/Advanced] add ability to block/unblock migration (PR [#8129](https://github.com/vatesfr/xen-orchestra/pull/8129))

### Bug fixes

Expand Down
2 changes: 2 additions & 0 deletions packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ const messages = {
vmWarmMigrationProcessInfo:
'Warm migration process will first create a copy of the VM on the destination while the source VM is still running, then shutdown the source VM and send the changes that happened during the migration to the destination to minimize downtime.',
backupLabel: 'Backup',
vmAllowMigration: 'Allow migration',
vmBlockMigration: 'Block migration',

// ----- SR general tab -----
baseCopyTooltip: '{n, number} base cop{n, plural, one {y} other {ies}} ({usage})',
Expand Down
20 changes: 19 additions & 1 deletion packages/xo-web/src/common/xo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ connect()

const _signIn = new Promise(resolve => xo.once('authenticated', resolve))

// eslint-disable-next-line n/no-unsupported-features/node-builtins
const _call = new URLSearchParams(window.location.search.slice(1)).has('debug')
? async (method, params) => {
await _signIn
const now = Date.now()
return tap.call(
xo.call(method, params),
result => {
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console, n/no-unsupported-features/node-builtins
console.debug('API call (%d ms)', Date.now() - now, method, params, result)
},
error => {
Expand Down Expand Up @@ -2441,6 +2442,23 @@ export const vmWarmMigration = async vm => {
})
}

export const vmBlockMigration = async vm => {
const reason = 'VM migration is blocked during backup'
return await _call('vm.set', { id: resolveId(vm), blockedOperations: { pool_migrate: reason, migrate_send: reason } })
}

export const vmAllowMigration = async vm => {
const reason = 'VM migration is blocked during backup'
const { pool_migrate, migrate_send } = vm.blockedOperations
return await _call('vm.set', {
id: resolveId(vm),
blockedOperations: {
migrate_send: migrate_send === undefined || migrate_send === reason ? null : migrate_send,
pool_migrate: pool_migrate === undefined || pool_migrate === reason ? null : pool_migrate,
},
})
}

// DISK ---------------------------------------------------------------

export const createDisk = (name, size, sr, { vm, bootable, mode, position }) =>
Expand Down
11 changes: 11 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 @@ -60,6 +60,8 @@ import {
vmDetachPcis,
vmSetUefiMode,
vmWarmMigration,
vmAllowMigration,
vmBlockMigration,
XEN_DEFAULT_CPU_CAP,
XEN_DEFAULT_CPU_WEIGHT,
XEN_VIDEORAM_VALUES,
Expand Down Expand Up @@ -721,6 +723,8 @@ export default class TabAdvanced extends Component {
vusbs,
} = this.props
const isWarmMigrationAvailable = getXoaPlan().value >= PREMIUM.value
const isMigrationAllowed =
vm.blockedOperations?.migrate_send === undefined && vm.blockedOperations?.pool_migrate === undefined
const addVtpmTooltip = this._getDisabledAddVtpmReason()
const deleteVtpmTooltip = this._getDisabledDeleteVtpmReason()
const host = this.props.vmHosts[vm.$container]
Expand Down Expand Up @@ -780,6 +784,13 @@ export default class TabAdvanced extends Component {
labelId='vmWarmMigration'
tooltip={isWarmMigrationAvailable ? undefined : _('availableXoaPremium')}
/>
<TabButton
btnStyle='warning'
handler={isMigrationAllowed ? vmBlockMigration : vmAllowMigration}
handlerParam={vm}
icon='vm-allow-migration'
labelId={isMigrationAllowed ? 'vmBlockMigration' : 'vmAllowMigration'}
/>
</span>
)}
{vm.power_state === 'Halted' && (
Expand Down

0 comments on commit 330965a

Please sign in to comment.