feat(host): update patches when joining pool (#560)

See vatesfr/xo-web#878
This commit is contained in:
Pierre Donias 2017-05-31 17:58:39 +02:00 committed by Julien Fontanet
parent c18b49a4a1
commit fec976a494
2 changed files with 43 additions and 0 deletions

View File

@ -1,4 +1,6 @@
import { format } from 'json-rpc-peer'
import { differenceBy } from 'lodash'
import { mapToArray } from '../utils'
// ===================================================================
@ -123,6 +125,23 @@ export {uploadPatch as patch}
// -------------------------------------------------------------------
export async function mergeInto ({ source, target, force }) {
const sourceHost = this.getObject(source.master)
const sourcePatches = sourceHost.patches
const targetPatches = this.getObject(target.master).patches
const counterDiff = differenceBy(sourcePatches, targetPatches, 'name')
if (counterDiff.length > 0) {
throw new Error('host has patches that are not applied on target pool')
}
const diff = differenceBy(targetPatches, sourcePatches, 'name')
// TODO: compare UUIDs
await this.getXapi(source).installSpecificPatchesOnHost(
mapToArray(diff, 'name'),
sourceHost._xapiId
)
await this.mergeXenPools(source._xapiId, target._xapiId, force)
}

View File

@ -1,5 +1,6 @@
import deferrable from 'golike-defer'
import every from 'lodash/every'
import find from 'lodash/find'
import includes from 'lodash/includes'
import isObject from 'lodash/isObject'
import some from 'lodash/some'
@ -389,6 +390,29 @@ export default {
: this.installPoolPatchOnHost(patch.uuid, host)
},
async installSpecificPatchesOnHost (patchNames, hostId) {
const host = this.getObject(hostId)
const missingPatches = await this._listMissingPoolPatchesOnHost(host)
const patchesToInstall = []
const addPatchesToList = patches => {
forEach(patches, patch => {
addPatchesToList(mapToArray(patch.requirements, { uuid: patch.uuid }))
if (!find(patchesToInstall, { name: patch.name })) {
patchesToInstall.push(patch)
}
})
}
addPatchesToList(mapToArray(patchNames, name =>
find(missingPatches, { name })
))
for (let i = 0, n = patchesToInstall.length; i < n; i++) {
await this._installPoolPatchAndRequirements(patchesToInstall[i], missingPatches, host)
}
},
async installAllPoolPatchesOnHost (hostId) {
let host = this.getObject(hostId)