Open GoogleCodeExporter opened 9 years ago
yes, I also get the same problem, how do you reslove this proble, can you tell
me.
my e-mai: john_xsj@hotmail.com
Original comment by xiaoshij...@gmail.com
on 10 Jun 2014 at 8:04
hello, I had resolve this problem, my code as follow:
import pysphere
def getHostByName(server, name):
mor = None
for host_mor, host_name in server.get_hosts().items():
if host_name == name: mor = host_mor; break
return mor
def getResourcePoolByName(server, resourcepool):
mor = None
for rp_mor, rp_path in server.get_resource_pools().items():
if resourcepool in rp_path : mor = rp_mor; break
return mor
def getDatastoreByName(server, name):
mor = None
for ds_mor, ds_path in server.get_datastores().items():
if ds_path == name: mor = ds_mor; break
return mor
def vmClone(name, vmTemplateName, resourcepool, host, datastore, sync):
#name: name of cloned VM;
#vmTemplateName: name of source template;
#labName: VM''s belong to a training lab;
#host: to deploy the VM on;
#labgroup: sequence number of lab system to use;
#sync: synchronous mode or not
vm = vCenterServer.get_vm_by_name(name=vmTemplateName)
host_mor = getHostByName(vCenterServer, host) #locate destination host MOR
rp_mor = getResourcePoolByName(vCenterServer,resourcepool) # locate default resource pool of destination host (the resource pool which parent folder is equal to the parent folder of the host)
ds_mor = getDatastoreByName(vCenterServer, datastore) # destination data store
if sync: # be careful, vm.clone returns different objects based on whether sync is true or false
clonedVM = vm.clone(name, sync_run=True, resourcepool=rp_mor, datastore=ds_mor, host=host_mor, power_on=False) # returns a VM object
return
else:
return vm.clone(name, sync_run=False, resourcepool=rp_mor, datastore=ds_mor, host=host_mor, power_on=False) # returns a VITask object
vCenterServer = pysphere.VIServer()
vCenterServer.connect('10.21.134.19', 'root', 'vmware')
print
vmClone("test_vm4","WIN7-Template-Neil-14","TIS17-2","10.21.120.14","tis17-bs-ti
ered",1)
Original comment by xiaoshij...@gmail.com
on 10 Jun 2014 at 9:43
Original issue reported on code.google.com by
dfrankes...@gmail.com
on 19 Feb 2014 at 6:38