From 8c05eab720e69ff83262be879078450dcfc6fb1b Mon Sep 17 00:00:00 2001 From: MlssFrncJrg <119158464+Pizzosaure@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:30:36 +0100 Subject: [PATCH] feat(xo-web/pool/patches): disable rolling pool update button (#7294) Fixes https://github.com/vatesfr/xen-orchestra/issues/6415 --- CHANGELOG.unreleased.md | 1 + packages/xo-web/src/common/intl/messages.js | 2 + .../xo-web/src/xo-app/pool/tab-patches.js | 42 ++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 603bcca00..441dc32bf 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -15,6 +15,7 @@ - [Pool/Advanced] Show pool backup/migration network even if they no longer exist (PR [#7303](https://github.com/vatesfr/xen-orchestra/pull/7303)) - [Import/disk] Couldn't update 'name' field when importing from a URL [#7326](https://github.com/vatesfr/xen-orchestra/issues/7326) (PR [#7332](https://github.com/vatesfr/xen-orchestra/pull/7332)) +- [Pool/patches] Disable Rolling Pool Update button if some powered up VMs are using a non-shared storage [#6415](https://github.com/vatesfr/xen-orchestra/issues/6415) (PR [#7294](https://github.com/vatesfr/xen-orchestra/pull/7294)) ### Packages to release diff --git a/packages/xo-web/src/common/intl/messages.js b/packages/xo-web/src/common/intl/messages.js index d38679d13..ec232c3d7 100644 --- a/packages/xo-web/src/common/intl/messages.js +++ b/packages/xo-web/src/common/intl/messages.js @@ -950,6 +950,8 @@ const messages = { insecureNbdConnection: 'Insecure NBD Connection (not allowed through XO)', // ----- Pool patches tab ----- multiHostPoolUpdate: "Rolling pool update can only work when there's multiple hosts in a pool with a shared storage", + nVmsRunningOnLocalStorage: + '{nVms, number} VM{nVms, plural, one {} other {s}} {nVms, plural, one {is} other {are}} currently running and using at least one local storage. A shared storage for all your VMs is needed to start a rolling pool update', // ----- Pool stats tab ----- poolNoStats: 'No stats', poolAllHosts: 'All hosts', diff --git a/packages/xo-web/src/xo-app/pool/tab-patches.js b/packages/xo-web/src/xo-app/pool/tab-patches.js index f386d51a4..fb258a13c 100644 --- a/packages/xo-web/src/xo-app/pool/tab-patches.js +++ b/packages/xo-web/src/xo-app/pool/tab-patches.js @@ -12,12 +12,16 @@ import { getXoaPlan, ENTERPRISE } from 'xoa-plans' import { installAllPatchesOnPool, installPatches, + isSrShared, + isSrWritable, rollingPoolUpdate, subscribeCurrentUser, subscribeHostMissingPatches, } from 'xo' +import filter from 'lodash/filter.js' import isEmpty from 'lodash/isEmpty.js' import size from 'lodash/size.js' +import some from 'lodash/some.js' const ROLLING_POOL_UPDATES_AVAILABLE = getXoaPlan().value >= ENTERPRISE.value @@ -173,8 +177,32 @@ const INSTALLED_PATCH_COLUMNS = [ poolId => host => host.$pool === poolId ) ), + runningVms: createGetObjectsOfType('VM').filter( + createSelector( + (_, props) => props.pool.id, + poolId => vm => vm.$pool === poolId && vm.power_state === 'Running' + ) + ), + vbds: createGetObjectsOfType('VBD'), + vdis: createGetObjectsOfType('VDI'), + srs: createGetObjectsOfType('SR'), }) export default class TabPatches extends Component { + getNVmsRunningOnLocalStorage = createSelector( + () => this.props.runningVms, + () => this.props.vbds, + () => this.props.vdis, + () => this.props.srs, + (runningVms, vbds, vdis, srs) => + filter(runningVms, vm => + some(vm.$VBDs, vbdId => { + const vbd = vbds[vbdId] + const vdi = vdis[vbd?.VDI] + const sr = srs[vdi?.$SR] + return !isSrShared(sr) && isSrWritable(sr) + }) + ).length + ) render() { const { hostPatches, @@ -189,6 +217,8 @@ export default class TabPatches extends Component { const isSingleHost = size(poolHosts) < 2 + const hasMultipleVmsRunningOnLocalStorage = this.getNVmsRunningOnLocalStorage() > 0 + return ( @@ -197,12 +227,20 @@ export default class TabPatches extends Component { {ROLLING_POOL_UPDATES_AVAILABLE && ( )}