From 094878cf8859113ff74140f5415b27e6fc7cf91c Mon Sep 17 00:00:00 2001 From: joseangelgm Date: Fri, 21 Dec 2018 13:01:20 +0100 Subject: [PATCH] Improve code for vcenter nic model Co-authored-by: semedi --- .../remotes/lib/vcenter_driver/virtual_machine.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index 1c0330bd72..0f3d3a3bb1 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -1232,20 +1232,17 @@ class VirtualMachine < VCenterDriver::Template unmanaged_nics.each do |unic| vnic = select.call(unic['BRIDGE']) - if unic['MODEL'] && !unic['MODEL'].empty? && !unic['MODEL'].nil? - vcenter_nic_class = vnic.class - opennebula_nic_class = nic_model_class(unic['MODEL']) - if vcenter_nic_class != opennebula_nic_class + vcenter_nic_class = vnic.class + new_model = unic['MODEL'] && !unic['MODEL'].empty? && !unic['MODEL'].nil? + opennebula_nic_class = nic_model_class(unic['MODEL']) if new_model + + if new_model && opennebula_nic_class != vcenter_nic_class # delete actual nic and update the new one. device_change << { :device => vnic, :operation => :remove } device_change << calculate_add_nic_spec(unic) - else + else vnic.macAddress = unic['MAC'] device_change << { :device => vnic, :operation => :edit } - end - else - vnic.macAddress = unic['MAC'] - device_change << { :device => vnic, :operation => :edit } end end end