feat(xo-server/pool.installPatches): restart toolstacks after install
Fixes https://kanban.vates.fr/b/jnfjuip4eBARBNuv9/xo-releases/t8QpqKnZ23iYnbRxR
This commit is contained in:
parent
0eb2ee72a4
commit
e7f9111ab5
13
packages/xo-server/src/_moveFirst.mjs
Normal file
13
packages/xo-server/src/_moveFirst.mjs
Normal file
@ -0,0 +1,13 @@
|
||||
export function moveFirst(array, predicate, thisArg) {
|
||||
const i = array.findIndex(predicate, thisArg)
|
||||
if (i === -1) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (i !== 0) {
|
||||
const item = array[0]
|
||||
array[0] = array[i]
|
||||
array[i] = item
|
||||
}
|
||||
return true
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
import { asyncMap } from '@xen-orchestra/async-map'
|
||||
import { defer as deferrable } from 'golike-defer'
|
||||
import { format } from 'json-rpc-peer'
|
||||
import { Ref } from 'xen-api'
|
||||
|
||||
import { moveFirst } from '../_moveFirst.mjs'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export async function set({
|
||||
@ -112,10 +115,27 @@ listMissingPatches.resolve = {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function installPatches({ pool, patches, hosts }) {
|
||||
await this.getXapi(hosts === undefined ? pool : hosts[0]).installPatches({
|
||||
patches,
|
||||
hosts,
|
||||
})
|
||||
const opts = { patches }
|
||||
let xapi
|
||||
if (pool !== undefined) {
|
||||
pool = this.getXapiObject(pool, 'pool')
|
||||
xapi = pool.$xapi
|
||||
hosts = Object.values(xapi.objects.indexes.type.host)
|
||||
} else {
|
||||
hosts = hosts.map(_ => this.getXapiObject(_))
|
||||
opts.hosts = hosts
|
||||
xapi = hosts[0].$xapi
|
||||
pool = xapi.pool
|
||||
}
|
||||
|
||||
await xapi.installPatches(opts)
|
||||
|
||||
const masterRef = pool.master
|
||||
if (moveFirst(hosts, _ => _.$ref === masterRef)) {
|
||||
await hosts.shift().$restartAgent()
|
||||
}
|
||||
|
||||
await asyncMap(hosts, host => host.$restartAgent())
|
||||
}
|
||||
|
||||
installPatches.params = {
|
||||
|
@ -307,12 +307,6 @@ export default {
|
||||
// INSTALL -------------------------------------------------------------------
|
||||
|
||||
async _xcpUpdate(hosts) {
|
||||
if (hosts === undefined) {
|
||||
hosts = filter(this.objects.all, { $type: 'host' })
|
||||
} else {
|
||||
hosts = filter(this.objects.all, obj => obj.$type === 'host' && hosts.includes(obj.$id))
|
||||
}
|
||||
|
||||
// XCP-ng hosts need to be updated one at a time starting with the pool master
|
||||
// https://github.com/vatesfr/xen-orchestra/issues/4468
|
||||
hosts = hosts.sort(({ $ref }) => ($ref === this.pool.master ? -1 : 1))
|
||||
|
Loading…
Reference in New Issue
Block a user