fix(xo-server/importDeltaVm): better network matching (#2834)

Fixes #2093
This commit is contained in:
Julien Fontanet 2018-04-07 01:00:19 +02:00 committed by GitHub
parent 55b35ac0cf
commit a7068ec166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -266,8 +266,8 @@ export default class Xapi extends XapiBase {
return value === null return value === null
? removal ? removal
: removal : removal
::ignoreErrors() ::ignoreErrors()
.then(() => this.call(add, ref, name, prepareXapiParam(value))) .then(() => this.call(add, ref, name, prepareXapiParam(value)))
} }
}) })
) )
@ -517,9 +517,9 @@ export default class Xapi extends XapiBase {
const onVmCreation = const onVmCreation =
nameLabel !== undefined nameLabel !== undefined
? vm => ? vm =>
targetXapi._setObjectProperties(vm, { targetXapi._setObjectProperties(vm, {
nameLabel, nameLabel,
}) })
: null : null
const vm = await targetXapi._getOrWaitObject( const vm = await targetXapi._getOrWaitObject(
@ -874,29 +874,30 @@ export default class Xapi extends XapiBase {
// Look for a snapshot of this vdi in the base VM. // Look for a snapshot of this vdi in the base VM.
const baseVdi = baseVdis[vdi.snapshot_of] const baseVdi = baseVdis[vdi.snapshot_of]
vdis[vdiRef] = vdis[vdiRef] = {
baseVdi && !disableBaseTags ...vdi,
? { other_config: {
...vdi, ...vdi.other_config,
other_config: { [TAG_BASE_DELTA]:
...vdi.other_config, baseVdi && !disableBaseTags ? baseVdi.uuid : undefined,
[TAG_BASE_DELTA]: baseVdi.uuid, },
}, $SR$uuid: vdi.$SR.uuid,
$SR$uuid: vdi.$SR.uuid, }
}
: {
...vdi,
$SR$uuid: vdi.$SR.uuid,
}
streams[`${vdiRef}.vhd`] = () => streams[`${vdiRef}.vhd`] = () =>
this._exportVdi($cancelToken, vdi, baseVdi, VDI_FORMAT_VHD) this._exportVdi($cancelToken, vdi, baseVdi, VDI_FORMAT_VHD)
}) })
const vifs = {} const vifs = {}
forEach(vm.$VIFs, vif => { forEach(vm.$VIFs, vif => {
const network = vif.$network
vifs[vif.$ref] = { vifs[vif.$ref] = {
...vif, ...vif,
$network$uuid: vif.$network.uuid, $network$uuid: network.uuid,
$network$name_label: network.name_label,
// https://github.com/babel/babel-eslint/issues/595
// eslint-disable-next-line no-undef
$network$VLAN: network.$PIFs[0]?.VLAN,
} }
}) })
@ -912,9 +913,9 @@ export default class Xapi extends XapiBase {
other_config: other_config:
baseVm && !disableBaseTags baseVm && !disableBaseTags
? { ? {
...vm.other_config, ...vm.other_config,
[TAG_BASE_DELTA]: baseVm.uuid, [TAG_BASE_DELTA]: baseVm.uuid,
} }
: omit(vm.other_config, TAG_BASE_DELTA), : omit(vm.other_config, TAG_BASE_DELTA),
}, },
}, },
@ -1029,10 +1030,21 @@ export default class Xapi extends XapiBase {
return newVdi return newVdi
})::pAll() })::pAll()
const networksOnPoolMasterByDevice = {} const networksByNameLabelByVlan = {}
let defaultNetwork let defaultNetwork
forEach(this.pool.$master.$PIFs, pif => { forEach(this.objects.all, object => {
defaultNetwork = networksOnPoolMasterByDevice[pif.device] = pif.$network if (object.$type === 'network') {
const pif = object.$PIFs[0]
if (pif === undefined) {
// ignore network
return
}
const vlan = pif.VLAN
const networksByNameLabel =
networksByNameLabelByVlan[vlan] ||
(networksByNameLabelByVlan[vlan] = {})
defaultNetwork = networksByNameLabel[object.name_label] = object
}
}) })
const { streams } = delta const { streams } = delta
@ -1069,10 +1081,21 @@ export default class Xapi extends XapiBase {
// Create VIFs. // Create VIFs.
asyncMap(delta.vifs, vif => { asyncMap(delta.vifs, vif => {
const network = let network =
(vif.$network$uuid && this.getObject(vif.$network$uuid, null)) || vif.$network$uuid && this.getObject(vif.$network$uuid, undefined)
networksOnPoolMasterByDevice[vif.device] ||
defaultNetwork if (network === undefined) {
const { $network$VLAN: vlan = -1 } = vif
const networksByNameLabel = networksByNameLabelByVlan[vlan]
if (networksByNameLabel !== undefined) {
network = networksByNameLabel[vif.$network$name_label]
if (network === undefined) {
network = networksByNameLabel[Object.keys(networksByNameLabel)[0]]
}
} else {
network = defaultNetwork
}
}
if (network) { if (network) {
return this._createVif(vm, network, vif) return this._createVif(vm, network, vif)