sasama1997
Contributor
Contributor

What do you specify for datastorePath?(SDK for Java)

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

110/110.vmdk NULL

vm_iscsi_1 NULL

Clone003/Clone003.vmdk NULL

esx1:storage1 NULL

NULL

NULL

Clone003/ NULL

Clone003 NULL

110/ NULL

110 NULL

/vm_iscsi_1/110/110.vmdk NULL

/vm_iscsi_1/110 NULL

/110 NULL

/Clone003 NULL

/Clone003/Clone003.vmdk 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

110/100.vmx NULL

Clone003/Clone003.vmx 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.

0 Kudos
2 Replies
admin
Immortal
Immortal

Generally whenever you need to supply the datastore path, you will need to specify the datastore name enclosed in [] ie.square brackets.

But, in your case, I just realized, datastore is a manged object only and does not extend managed entity. FindByInventoryPath method works only for managed entities and thus will not return a mor to the datastore.

In order to get a mor to a datastore, you may use, FindByInventoryPath to get a mor to a Datacenter and then retrieve it's property datastore, which will list the array of managed object references to the datastores on this datacenter.

There are other ways of retrieving managed object refererence to the datastore. e.g. You may get a managed object refererence to a host, using either FindByIp, FindByInventoryPath, FindByUuid etc and retrieve it's property datastore, which will return an array of managed object referernces to datastores

0 Kudos
sasama1997
Contributor
Contributor

Thank you.

It was possible to do.

The revision part is the following.

//********************************************************

VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();

VirtualDisk disk = null;

VirtualMachineConfigInfo vmConfigInfo =

(VirtualMachineConfigInfo)cb.getServiceUtil().getDynamicProperty(_virtualMachine, "config");

VirtualDiskFlatVer2BackingInfo diskfileBacking

= new VirtualDiskFlatVer2BackingInfo();

VirtualDevice [] test = vmConfigInfo.getHardware().getDevice();

for(int k=0;k

if(test[k].getDeviceInfo().getLabel().equalsIgnoreCase(

cb.get_option("value"))){

disk = (VirtualDisk)test[k];

}

}

if(disk != null) {

int size = 1024 * 1024 * 26;

disk.setCapacityInKB(size);

diskSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);

//diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.replace);

diskSpec.setDevice(disk);

}

if (diskSpec != null){

VirtualDeviceConfigSpec [] vdiskSpecArray = {diskSpec};

vmConfigSpec.setDeviceChange(vdiskSpecArray);

}

//**********************************************************

0 Kudos