Skip to content

Commit

Permalink
Add disk relocate spec start
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jul 19, 2019
1 parent 1ff3e7b commit ae6c71c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def prepare_for_clone_task
:pool => dest_resource_pool,
:storage_profile => dest_storage_profile,
:config => build_config_spec,
:customization => build_customization_spec,
:transform => build_transform_spec
:customization => build_customization_spec
}

# Determine if we are doing a linked-clone provision
Expand Down Expand Up @@ -120,6 +119,7 @@ def start_clone(clone_options)
vim_clone_options[key] = ci.ems_ref_obj
end

vim_clone_options[:disk] = build_disk_relocate_spec(clone_options)
vim_clone_options[:datastore] = datastore_ems_ref(clone_options)
vim_clone_options[:storage_profile] = build_storage_profile(clone_options[:storage_profile]) unless clone_options[:storage_profile].nil?

Expand Down Expand Up @@ -184,13 +184,6 @@ def get_selected_snapshot
ss
end

def build_transform_spec
case get_option(:disk_format)
when 'thin' then VimString.new('sparse', "VirtualMachineRelocateTransformation")
when 'thick' then VimString.new('flat', "VirtualMachineRelocateTransformation")
end
end

def build_storage_profile(storage_profile)
VimArray.new('ArrayOfVirtualMachineProfileSpec') do |vm_profile_spec_array|
vm_profile_spec_array << VimHash.new('VirtualMachineDefinedProfileSpec') do |vm_profile_spec|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,35 @@ def build_config_disk_spec(vmcs)
end
end

def get_scsi_controller_info
inventory_hash = source.with_provider_connection do |vim|
vim.virtualMachineByMor(source.ems_ref_obj)
def build_disk_relocate_spec(clone_options)
VimArray.new('ArrayOfVirtualMachineRelocateSpec') do |vm_relocate_spec_array|
vm_relocate_spec_array << VimHash.new('VirtualMachineRelocateSpecDiskLocator') do |vm_relocate_spec_disk_locator|
(disks_info + get_new_disks).map do |disk|
vm_relocate_spec_disk_locator.diskId = disk.key
vm_relocate_spec_disk_locator.datastore = disk["backing"]["datastore"]
vm_relocate_spec_disk_locator.diskBackingInfo = VimHash.new("VirtualDiskFlatVer2BackingInfo") do |vdbi|
case get_option(:disk_format)
when 'thin'
vdbi.thinProvisioned = true
when 'thick'
vdbi.thinProvisioned = false
vdbi.eagerlyScrub = false
when 'thick_eager'
vdbi.eagerlyScrub = true
vdbi.thinProvisioned = false
end
end
end
end
end
end

def disks_info
disks.select { |d| d.xsiType == "VirtualDisk" }
end

devs = inventory_hash.fetch_path("config", "hardware", "device") || []
devs.each_with_object({}) do |dev, h|
def get_scsi_controller_info
disks.each_with_object({}) do |dev, h|
next unless dev.fetch_path("deviceInfo", "label").to_s =~ /^SCSI\s[Cc]ontroller\s.*$/
h[dev['busNumber'].to_i] = dev
end
Expand Down Expand Up @@ -79,4 +101,14 @@ def add_disk(vmcs, disk, controller, new_dev_key)
end
end
end

private

def disks
inventory_hash = source.with_provider_connection do |vim|
vim.virtualMachineByMor(source.ems_ref_obj)
end

inventory_hash.fetch_path("config", "hardware", "device") || []
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
expect(spec["annotation"]).to include(@vm_prov.phase_context[:new_vm_validation_guid])
end

it "should return a transform spec" do
spec = @vm_prov.build_transform_spec
expect(spec).to be_nil
it "should return a disk_relocate spec" do
@vm_prov.options[:disk_format] = 'thin'
spec = @vm_prov.build_transform_spec
expect(spec).to be_kind_of(VimString)
expect(spec.vimType).to eq('VirtualMachineRelocateTransformation')
@vm_prov.destination = @vm_template
spec = @vm_prov.build_disk_relocate_spec(@vm_prov.options)
expect(spec).to be_kind_of(VimHash)
expect(spec.vimType).to eq('VirtualDiskFlatVer2BackingInfo')
expect(spec["disk_format"]).to eq('thin')
end

it "should detect when a reconfigure_hardware_on_destination call is required" do
Expand Down

0 comments on commit ae6c71c

Please sign in to comment.