Skip to content

Commit

Permalink
feat(xo-server/pool.installPatches): restart toolstacks after install
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-f committed Mar 21, 2022
1 parent 0eb2ee7 commit e7f9111
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
13 changes: 13 additions & 0 deletions packages/xo-server/src/_moveFirst.mjs
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 24 additions & 4 deletions packages/xo-server/src/api/pool.mjs
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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 = {
Expand Down
6 changes: 0 additions & 6 deletions packages/xo-server/src/xapi/mixins/patching.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit e7f9111

Please sign in to comment.