mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
B #2652: bootOrder works for unmanaged disks
B #2652: grab controller information from disks
This commit is contained in:
parent
20b37ea7cc
commit
ed207e0d6e
@ -156,6 +156,12 @@ class VirtualMachine < VCenterDriver::Template
|
||||
@vc_res[:device]
|
||||
end
|
||||
|
||||
def node
|
||||
raise @error_message unless exists?
|
||||
|
||||
@vc_res[:tag]
|
||||
end
|
||||
|
||||
def path
|
||||
raise @error_message unless exists?
|
||||
|
||||
@ -962,7 +968,7 @@ class VirtualMachine < VCenterDriver::Template
|
||||
unmanaged_disks = one_item.retrieve_xmlelements(xpath)
|
||||
|
||||
# unmanaged disks:
|
||||
if !unmanaged_disks.empty?
|
||||
if !unmanaged_disks.empty? && !instantiated_as_persistent?
|
||||
|
||||
# Get vcenter VM disks to know real path of cloned disk
|
||||
vcenter_disks = get_vcenter_disks
|
||||
@ -1141,6 +1147,28 @@ class VirtualMachine < VCenterDriver::Template
|
||||
extra_config
|
||||
end
|
||||
|
||||
SUPPORTED_DEV = ['disk']
|
||||
def set_boot_order(boot_info)
|
||||
convert = -> (device_str){
|
||||
spl = device_str.scan(/^disk|\d+$/)
|
||||
if !SUPPORTED_DEV.include?(spl[0])
|
||||
raise "#{device_str} is not supported in boot order"
|
||||
end
|
||||
|
||||
for i in 0..1
|
||||
device = send(spl[0], *[spl[1]])
|
||||
break if device.exists?
|
||||
sync_disks
|
||||
end
|
||||
|
||||
RbVmomi::VIM.VirtualMachineBootOptionsBootableDiskDevice({deviceKey: device.key})
|
||||
}
|
||||
|
||||
boot_order = boot_info.split(',').map{ |str| convert.call(str) }
|
||||
|
||||
RbVmomi::VIM.VirtualMachineBootOptions({bootOrder: boot_order})
|
||||
end
|
||||
|
||||
# TODO
|
||||
# Synchronize the OpenNebula VM representation with vCenter VM
|
||||
def sync(deploy = {})
|
||||
@ -1148,7 +1176,7 @@ class VirtualMachine < VCenterDriver::Template
|
||||
device_change = []
|
||||
|
||||
# deploy operation, no instantiated as persistent
|
||||
if deploy[:template_ref] && !instantiated_as_persistent?
|
||||
if deploy[:template_ref]
|
||||
template_ref = deploy[:template_ref]
|
||||
refs = reference_unmanaged_devices(template_ref)
|
||||
|
||||
@ -1157,9 +1185,13 @@ class VirtualMachine < VCenterDriver::Template
|
||||
extraconfig += refs[:extraConfig] if refs[:extraConfig]
|
||||
end
|
||||
|
||||
info_disks
|
||||
if deploy[:boot] && !deploy[:boot].empty?
|
||||
boot_opts = set_boot_order(deploy[:boot])
|
||||
end
|
||||
|
||||
nresize_unmanaged_disks
|
||||
|
||||
info_disks
|
||||
disks = sync_disks(:all, false)
|
||||
|
||||
# changes from sync_disks
|
||||
@ -1186,6 +1218,7 @@ class VirtualMachine < VCenterDriver::Template
|
||||
:extraConfig => extraconfig,
|
||||
:deviceChange => device_change
|
||||
}
|
||||
spec_hash[:bootOptions] = boot_opts if boot_opts
|
||||
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
|
||||
|
||||
@ -2258,6 +2291,9 @@ class VirtualMachine < VCenterDriver::Template
|
||||
|
||||
# Update the template reference
|
||||
new_template.update("VCENTER_TEMPLATE_REF=#{@item._ref}", true)
|
||||
if !new_template['TEMPLATE/OS'] || new_template['TEMPLATE/OS'].empty?
|
||||
new_template.update('OS=[BOOT="disk0"]', true)
|
||||
end
|
||||
end
|
||||
|
||||
# TODO
|
||||
|
@ -570,20 +570,24 @@ class Template
|
||||
ide_controlled = []
|
||||
sata_controlled = []
|
||||
scsi_controlled = []
|
||||
controller = {}
|
||||
|
||||
@item["config.hardware.device"].each do |device|
|
||||
disk = {}
|
||||
|
||||
if device.is_a? RbVmomi::VIM::VirtualIDEController
|
||||
ide_controlled.concat(device.device)
|
||||
controller[device.key] = "ide#{device.busNumber}"
|
||||
end
|
||||
|
||||
if device.is_a? RbVmomi::VIM::VirtualSATAController
|
||||
sata_controlled.concat(device.device)
|
||||
controller[device.key] = "sata#{device.busNumber}"
|
||||
end
|
||||
|
||||
if device.is_a? RbVmomi::VIM::VirtualSCSIController
|
||||
scsi_controlled.concat(device.device)
|
||||
controller[device.key] = "scsi#{device.busNumber}"
|
||||
end
|
||||
|
||||
if is_disk_or_iso?(device)
|
||||
@ -596,6 +600,8 @@ class Template
|
||||
disk[:prefix] = "hd" if ide_controlled.include?(device.key)
|
||||
disk[:prefix] = "sd" if scsi_controlled.include?(device.key)
|
||||
disk[:prefix] = "sd" if sata_controlled.include?(device.key)
|
||||
disk[:tag] = "#{controller[device.controllerKey]}:#{device.unitNumber}"
|
||||
|
||||
disks << disk
|
||||
end
|
||||
end
|
||||
|
@ -55,6 +55,7 @@ begin
|
||||
vm = VCenterDriver::VirtualMachine.new_one(vi_client, deploy_id, one_vm)
|
||||
else
|
||||
deploy[:template_ref] = drv_action['USER_TEMPLATE/VCENTER_TEMPLATE_REF']
|
||||
deploy[:boot] = drv_action['TEMPLATE/OS']
|
||||
vm = VCenterDriver::VirtualMachine.new_from_clone(vi_client,
|
||||
drv_action,
|
||||
vm_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user