mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add the ability to create linked clones in vsphere
This commit is contained in:
parent
d97384b19e
commit
8e341ad831
1 changed files with 34 additions and 3 deletions
|
@ -70,10 +70,41 @@ module Fog
|
|||
esx_host = vm_mob_ref.collect!('runtime.host')['runtime.host']
|
||||
# The parent of the ESX host itself is a ComputeResource which has a resourcePool
|
||||
resource_pool = esx_host.parent.resourcePool
|
||||
|
||||
# Next, create a Relocation Spec instance
|
||||
relocation_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => resource_pool,
|
||||
relocation_spec=nil
|
||||
if ( options['linked_clone'] )
|
||||
# cribbed heavily from the rbvmomi clone_vm.rb
|
||||
# this chunk of code reconfigures the disk of the clone source to be read only,
|
||||
# and then creates a delta disk on top of that, this is required by the API in order to create
|
||||
# linked clondes
|
||||
disks=vm_mob_ref.config.hardware.device.select{|vm_device| vm_device.class == RbVmomi::VIM::VirtualDisk}
|
||||
disks.select{|vm_device| vm_device.backing.parent == nil}.each do |disk|
|
||||
disk_spec = {
|
||||
:deviceChange => [
|
||||
{
|
||||
:operation => :remove,
|
||||
:device => disk
|
||||
},
|
||||
{
|
||||
:operation => :add,
|
||||
:fileOperation => :create,
|
||||
:device => disk.dup.tap{|disk_backing|
|
||||
disk_backing.backing = disk_backing.backing.dup;
|
||||
disk_backing.backing.fileName = "[#{disk.backing.datastore.name}]";
|
||||
disk_backing.backing.parent = disk.backing
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
vm_mob_ref.ReconfigVM_Task(:spec => disk_spec).wait_for_completion
|
||||
end
|
||||
# Next, create a Relocation Spec instance
|
||||
relocation_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => resource_pool,
|
||||
:diskMoveType => :moveChildMostDiskBacking)
|
||||
|
||||
else
|
||||
relocation_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => resource_pool,
|
||||
:transform => options['transform'] || 'sparse')
|
||||
end
|
||||
# And the clone specification
|
||||
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => relocation_spec,
|
||||
:powerOn => options['power_on'] || true,
|
||||
|
|
Loading…
Add table
Reference in a new issue