def clone_vm(content, template, vm_name, si, datacenter_name, vm_folder, datastore_name, cluster_name, resource_pool, power_on):
 datacenter = get_obj(content, [vim.Datacenter], datacenter_name)
 if vm_folder:
  destfolder = get_obj(content, [vim.Folder], vm_folder)
 else:
  destfolder = datacenter.vmFolder
 if datastore_name:
  datastore = get_obj(content, [vim.Datastore], datastore_name)
 else:
  datastore = get_obj(content, [vim.Datastore], template.datastore[0].info.name)
 cluster = get_obj(content, [vim.ClusterComputeResource], cluster_name)
 if resource_pool:
  resource_pool = get_obj(content, [vim.ResourcePool], resource_pool)
 else:
  resource_pool = cluster.resourcePool
 relospec = vim.vm.RelocateSpec()
 relospec.datastore = datastore
 relospec.pool = resource_pool
 clonespec = vim.vm.CloneSpec()
 clonespec.location = relospec
 clonespec.powerOn = power_on
 print 'cloning VM...'
 task = template.Clone(folder=destfolder, name=vm_name, spec=clonespec)
 wait_for_task(task)

def clone_vm ( content , template , vm_name , si , datacenter_name , vm_folder , datastore_name , cluster_name , resource_pool , power_on ) : datacenter = get_obj ( content , [ vim . Datacenter ] , datacenter_name ) if vm_folder : destfolder = get_obj ( content , [ vim . Folder ] , vm_folder ) else : destfolder = datacenter . vmFolder if datastore_name : datastore = get_obj ( content , [ vim . Datastore ] , datastore_name ) else : datastore = get_obj ( content , [ vim . Datastore ] , template . datastore [ 0 ] . info . name ) cluster = get_obj ( content , [ vim . ClusterComputeResource ] , cluster_name ) if resource_pool : resource_pool = get_obj ( content , [ vim . ResourcePool ] , resource_pool ) else : resource_pool = cluster . resourcePool relospec = vim . vm . RelocateSpec ( ) relospec . datastore = datastore relospec . pool = resource_pool clonespec = vim . vm . CloneSpec ( ) clonespec . location = relospec clonespec . powerOn = power_on print 'cloning VM...' task = template . Clone ( folder = destfolder , name = vm_name , spec = clonespec ) wait_for_task ( task )
clone a vm from a template/vm .