Skip to content

Commit

Permalink
feat(xo-web/pool/patches): disable rolling pool update button (#7294)
Browse files Browse the repository at this point in the history
Fixes #6415
  • Loading branch information
Pizzosaure committed Jan 30, 2024
1 parent 4db605f commit 8c05eab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 @@ -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',
Expand Down
42 changes: 40 additions & 2 deletions packages/xo-web/src/xo-app/pool/tab-patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -189,6 +217,8 @@ export default class TabPatches extends Component {

const isSingleHost = size(poolHosts) < 2

const hasMultipleVmsRunningOnLocalStorage = this.getNVmsRunningOnLocalStorage() > 0

return (
<Upgrade place='poolPatches' required={2}>
<Container>
Expand All @@ -197,12 +227,20 @@ export default class TabPatches extends Component {
{ROLLING_POOL_UPDATES_AVAILABLE && (
<TabButton
btnStyle='primary'
disabled={isEmpty(missingPatches) || isSingleHost}
disabled={isEmpty(missingPatches) || hasMultipleVmsRunningOnLocalStorage || isSingleHost}
handler={rollingPoolUpdate}
handlerParam={pool.id}
icon='pool-rolling-update'
labelId='rollingPoolUpdate'
tooltip={isSingleHost ? _('multiHostPoolUpdate') : undefined}
tooltip={
hasMultipleVmsRunningOnLocalStorage
? _('nVmsRunningOnLocalStorage', {
nVms: this.getNVmsRunningOnLocalStorage(),
})
: isSingleHost
? _('multiHostPoolUpdate')
: undefined
}
/>
)}
<TabButton
Expand Down

0 comments on commit 8c05eab

Please sign in to comment.