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

@ -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, ...vdi,
other_config: { other_config: {
...vdi.other_config, ...vdi.other_config,
[TAG_BASE_DELTA]: baseVdi.uuid, [TAG_BASE_DELTA]:
baseVdi && !disableBaseTags ? baseVdi.uuid : undefined,
}, },
$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,
} }
}) })
@ -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)