Hello.
For me, English is a beginner.
I try to make the clone of a virtual machine in the state of power off by CloneVM_Task now.
It refers to VMClone.java that exists in the sample source file at
that time.
However, the method of changing Datastore the clone making ahead is
not understood.
Person welcome that someone understands?
Actually, it is thought as follows that Datastore the clone ahead is specified for VirtualMachineRelocateSpec of the source that is.
However, neither a set item nor a set value are understood.
/****************************************************/
//VMClone.java
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
//*******What do you put in here?*******
cloneSpec.setLocation(relocSpec);
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
String clonedName = cloneName;
System.out.println("Launching clone task to create a clone: "
+ clonedName);
try {
ManagedObjectReference cloneTask
= service.cloneVM_Task(vmRef, vmFolderRef, clonedName, cloneSpec);
String status = cb.getServiceUtil().waitForTask(cloneTask);
if(status.equalsIgnoreCase("failure")) {
System.out.println("Failure -: Virtual Machine cannot be cloned");
}
if(status.equalsIgnoreCase("sucess")) {
System.out.println("Virtual Machine Cloned successfully.");
}
}
/****************************************************/
I survive terribly if this is understood.
It asks suitably.
The key to finding the details on the properties of dataobjects, is the Reference Guide. Please refer:
If you browse the CloneSpec, which needs to be passed when cloning a virtual machine, you can provide the RelocationSpec as well. It allows to move a virtual machine to a different datastore or a host. In case you are intereseted in changing the datastore, you would first need to obtain a managed object reference to a datastore to which you would want your cloned machine to reside on, and then pass this Managed Object Reference in the VirtualMachineRelocate Spec.
ManagedObjectReference datastoreRef
= S1.getService().findByInventoryPath(content.getSearchIndex(), datastorePath);
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
relocSpec.setDatastore(datastoreRef);
cloneSpec.setLocation(relocSpec);
Thank you for the answer.
Does it only have to be substituted for "DatastorePath" URL of datastore that wants to
make VirtualMachine?
For instance, does it only have to be substituted URL of datastore "/vmfs/volumes/?"?
The use of the data object of "ManagedObjectReference" type might not be so understood.
For instance, are the following source codes correct directions?
/**************************************************/
/*****/
String datastorePath = "/vmfs/volumes/XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXXXXXX";
/*****/
ManagedObjectReference datastoreRef
= S1.getService().findByInventoryPath(content.getSearchIndex(), datastorePath);
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
relocSpec.setDatastore(datastoreRef);
cloneSpec.setLocation(relocSpec);
/*************************************************/
Hello.
I try to make the clone of a virtual machine from the template.
The template is in Datastore named .
I want to make the clone of a virtual machine in Datastore named
based on this template.
However, Datastore cannot be changed in the sample source named
VMClone.java of "VMware SDK for java".
Then, VMClone.java was corrected as follows.
//**********************************************************************
// TODO Set of clone method
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
// **********************************************************************
// TODO Setting of datastorePath
if (datastorePath != null && !"".equals(datastorePath.trim())) {
ManagedObjectReference datastoreRef = S1.getService()
.findByInventoryPath(content.getSearchIndex(),
datastorePath);
relocSpec.setDatastore(datastoreRef);
} else {
// The clone is done in the same datastore.
}
// **********************************************************************
cloneSpec.setLocation(relocSpec);
// TODO Setting of operation status
cloneSpec.setPowerOn(false);
// TODO Setting whether to use template file
cloneSpec.setTemplate(false);
//***********************************************************************
Moreover, the following patterns were substituted for datastorePath and it
examined it.
datastorePath datastoreRef
vm_iscsi_1 NULL
esx1:storage1 NULL
/vm_iscsi_1/110/110.vmdk NULL
/vm_iscsi_1/110 NULL
/[esx1:storage1]/Clone003/Clone003.vmdk NULL
/esx1:storage1/Clone003/Clone003.vmdk NULL
/esx1:storage1/Clone003 NULL
/[vm_iscsi_1]/110/110.vmdk NULL
/[vm_iscsi_1]/110 NULL
/vmfs/volumes/47ff3a37-59398f00-c5df-001e0bea2efa NULL
"NULL" is substituted for datastoreRef always.
Do you pat it?
Does trying to acquire MoRef with findByInventoryPath() make a mistake?
Moreover, what should I substitute for datastorePath?
My best regards.
http://communities.vmware.com/message/1031344
Had the same question...
Found an answer.
See my post, let me know if it helps.
M@
Thank you!!
It was possible to do.
//***********************************************************
ManagedObjectReference [] datastoreRef
= (ManagedObjectReference [])cb.getServiceUtil().getDynamicProperty(
datacenterRef,"datastore");
//************************************************************