mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +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).
This commit is contained in:
parent
f738a4c760
commit
588f7084c5
@ -1252,6 +1252,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)
|
||||
@ -1637,6 +1638,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
|
||||
@ -1673,7 +1705,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
|
||||
|
||||
@ -1758,6 +1790,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