From 45a0ff26c5a7b7e6c54ce53be6954f0710578102 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 24 Mar 2021 16:38:19 +0100 Subject: [PATCH] feat(xapi/VIF_create): MAC must be passed explicitely --- @xen-orchestra/backups/_deltaVm.js | 15 ++++++++----- @xen-orchestra/xapi/src/vif.js | 34 ++++++++++++++++++------------ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/@xen-orchestra/backups/_deltaVm.js b/@xen-orchestra/backups/_deltaVm.js index 7e3ef0723..ab23e2689 100644 --- a/@xen-orchestra/backups/_deltaVm.js +++ b/@xen-orchestra/backups/_deltaVm.js @@ -325,11 +325,16 @@ exports.importDeltaVm = defer(async function importDeltaVm( } if (network) { - return xapi.VIF_create({ - ...vif, - network: network.$ref, - VM: vmRef, - }) + return xapi.VIF_create( + { + ...vif, + network: network.$ref, + VM: vmRef, + }, + { + MAC: vif.MAC, + } + ) } }), ]) diff --git a/@xen-orchestra/xapi/src/vif.js b/@xen-orchestra/xapi/src/vif.js index 81de42335..b0b6cea11 100644 --- a/@xen-orchestra/xapi/src/vif.js +++ b/@xen-orchestra/xapi/src/vif.js @@ -1,20 +1,26 @@ const isVmRunning = require('./_isVmRunning') module.exports = class Vif { - async create({ - currently_attached = true, - device, - ipv4_allowed, - ipv6_allowed, - locking_mode, - MAC, - MTU, - network, - other_config = {}, - qos_algorithm_params = {}, - qos_algorithm_type = '', - VM, - }) { + async create( + { + currently_attached = true, + device, + ipv4_allowed, + ipv6_allowed, + locking_mode, + MTU, + network, + other_config = {}, + qos_algorithm_params = {}, + qos_algorithm_type = '', + VM, + }, + { + // duplicated MAC addresses can lead to issues, + // therefore it should be passed explicitely + MAC = '', + } = {} + ) { const [powerState, ...rest] = await Promise.all([ this.getField('VM', VM, 'power_state'), device ?? (await this.call('VM.get_allowed_VIF_devices', VM))[0],