mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1217 from endzyme/patch-1
Update lib/fog/vsphere/requests/compute/vm_clone.rb
This commit is contained in:
commit
aa0e825037
1 changed files with 11 additions and 6 deletions
|
@ -34,13 +34,16 @@ module Fog
|
|||
# Option handling
|
||||
options = vm_clone_check_options(options)
|
||||
|
||||
# Added for people still using options['path']
|
||||
template_path = options['path'] || options['template_path']
|
||||
|
||||
notfound = lambda { raise Fog::Compute::Vsphere::NotFound, "Could not find VM template" }
|
||||
|
||||
# Find the template in the folder. This is more efficient than
|
||||
# searching ALL VM's looking for the template.
|
||||
# Tap gets rid of the leading empty string and "Datacenters" element
|
||||
# and returns the array.
|
||||
path_elements = options['path'].split('/').tap { |ary| ary.shift 2 }
|
||||
path_elements = template_path.split('/').tap { |ary| ary.shift 2 }
|
||||
# The DC name itself.
|
||||
template_dc = path_elements.shift
|
||||
# If the first path element contains "vm" this denotes the vmFolder
|
||||
|
@ -69,10 +72,10 @@ module Fog
|
|||
# Now find the template itself using the efficient find method
|
||||
vm_mob_ref = folder.find(template_name, RbVmomi::VIM::VirtualMachine)
|
||||
|
||||
# Now find _a_ resource pool to use for the clone
|
||||
# (REVISIT: We need to support cloning into a specific RP)
|
||||
|
||||
if ( vm_mob_ref.resourcePool == nil )
|
||||
# Now find _a_ resource pool to use for the clone if one is not specified
|
||||
if ( options.has_key?('resource_pool') )
|
||||
resource_pool = options['resource_pool']
|
||||
elsif ( vm_mob_ref.resourcePool == nil )
|
||||
# If the template is really a template then there is no associated resource pool,
|
||||
# so we need to find one using the template's parent host or cluster
|
||||
esx_host = vm_mob_ref.collect!('runtime.host')['runtime.host']
|
||||
|
@ -125,7 +128,9 @@ module Fog
|
|||
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => relocation_spec,
|
||||
:powerOn => options.has_key?('power_on') ? options['power_on'] : true,
|
||||
:template => false)
|
||||
task = vm_mob_ref.CloneVM_Task(:folder => vm_mob_ref.parent, :name => options['name'], :spec => clone_spec)
|
||||
task = vm_mob_ref.CloneVM_Task(:folder => options.has_key?('dest_folder') ? options['dest_folder'] : vm_mob_ref.parent,
|
||||
:name => options['name'],
|
||||
:spec => clone_spec)
|
||||
# Waiting for the VM to complete allows us to get the VirtulMachine
|
||||
# object of the new machine when it's done. It is HIGHLY recommended
|
||||
# to set 'wait' => true if your app wants to wait. Otherwise, you're
|
||||
|
|
Loading…
Add table
Reference in a new issue