mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
B 4087: Fix incorrect disk keys (#4101)
Fix an error when creating a new disk. The key value stored into the extraconfig in the vm could have a different value than the value into the vcenter managed object browser (MOB). (cherry picked from commit 588f7084c59703aff75d9f30d7ddb98f54be4e01)
This commit is contained in:
parent
c81e21523a
commit
eed0ac324d
@ -1191,6 +1191,7 @@ module VCenterDriver
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
|
||||
|
||||
@item.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
sync_extraconfig_disk(spec_hash)
|
||||
end
|
||||
|
||||
def extraconfig_file(file, id)
|
||||
@ -1576,6 +1577,37 @@ module VCenterDriver
|
||||
return detach_disk_array, extra_config
|
||||
end
|
||||
|
||||
def different_key?(change_disk, vc_disk)
|
||||
change_disk[:device].controllerKey == vc_disk.controllerKey &&
|
||||
change_disk[:device].unitNumber == vc_disk.unitNumber &&
|
||||
change_disk[:device].key != vc_disk.key
|
||||
end
|
||||
|
||||
def sync_extraconfig_disk(spec_hash)
|
||||
return if spec_hash[:deviceChange].empty?
|
||||
extraconfig_new = []
|
||||
# vCenter mob disks
|
||||
vc_disks = @item["config.hardware.device"].select do |vc_device|
|
||||
is_disk?(vc_device)
|
||||
end
|
||||
return unless vc_disks
|
||||
# For each changed disk, compare with vcenter mob disk
|
||||
spec_hash[:deviceChange].each_with_index do |device, index|
|
||||
change_disk = spec_hash[:deviceChange][index]
|
||||
vc_disks.each do |vc_disk|
|
||||
if different_key?(change_disk, vc_disk)
|
||||
extraconfig_new << {key: spec_hash[:extraConfig][index][:key],
|
||||
value: vc_disk.key.to_s}
|
||||
end
|
||||
end
|
||||
end
|
||||
unless extraconfig_new.empty?
|
||||
spec_hash = {:extraConfig => extraconfig_new}
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
|
||||
@item.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
end
|
||||
|
||||
# sync OpenNebula disk model with vCenter
|
||||
#
|
||||
# @param option [symbol] if :all is provided the method will try to sync
|
||||
@ -1612,7 +1644,7 @@ module VCenterDriver
|
||||
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
|
||||
@item.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
|
||||
###sync_extraconfig_disk(spec_hash)
|
||||
info_disks
|
||||
end
|
||||
|
||||
@ -1697,6 +1729,8 @@ module VCenterDriver
|
||||
else
|
||||
@item.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
# Modify extraConfig if disks has a bad key
|
||||
sync_extraconfig_disk(spec_hash)
|
||||
rescue Exception => e
|
||||
raise "Cannot attach DISK to VM: #{e.message}\n#{e.backtrace.join("\n")}"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user