Hi,
I am using Java API to create a client similar to vSphere. But the problem I face is of create a new VM.
So, I am using something like:
When using CreateVM_Task against vCenter connection I always leave the host parameter null so vCenter places itself.
Odd that the code works against host directly - means you most likely have your config spec correct.
datastore path name syntax is: "[" + datastoreName + "]/" + vm.name + "/" + vm.name + ".vmx"
I also tried to create VM against vCenter and it fails.
I use "null" as host parameter and "[" + dataStoreName+ "]/" + vmName + "/" + vmName + ".vmx" as datastore path.
Here is my code:
final VirtualMachineFileInfo vmfi = new VirtualMachineFileInfo();vmfi.setVmPathName("[" + dataStoreName+ "]/" + vmName + "/" + vmName + ".vmx" );vmSpec.setFiles(vmfi);final Task task = vmFolder.createVM_Task(config, pool, null);
I have checked vmPathName already exists vm and it looks like "[ dataStoreName ] vmName/ vmName.vmx".
I tried to use this format but with no success.
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
vmConfigSpec.setName("abcab");
vmConfigSpec.setAnnotation("VirtualMachine Annotation");
vmConfigSpec.setMemoryMB(Long.parseLong("1024"));
vmConfigSpec.setNumCPUs(2);
VirtualMachineFileInfo files = new VirtualMachineFileInfo();
files.setVmPathName("[test1] abcab/abcab.vmx");
vmConfigSpec.setFiles(files);
folder.createVM_Task(vmConfigSpec, resourcePool, hostSystem);
this my code is successed; give me you error message;
may be you folder instance is error;
the folder.getChildType() must include VirtualMachine
>folder.getChildType()
[Folder, VirtualMachine, VirtualApp]
>vmfi.getVmPathName()
[DatastoreName] vmName/vmName.vmx
Exception: com.vmware.vim25.InvalidDatastorePath
Invalid datastore path '[DatastoreName] vmName/vmName.vmx'.
The same command works properly when connected to ESX.
Exception: com.vmware.vim25.InvalidDatastorePath
are you sure [DatastoreName] vmName/vmName.vmx exist?
first you sure datastore (ManagedEntity)‘s name is DatastoreName
and you can try this path [DatastoreName] vmName1/vmName1.vmx
Has this issue been resolved? I think it is a bug of vSphere SDK, do you know the bug id? Thanks in advance!
Most probably you have several hosts in a vCenter and the host mor you specified for CreateVM task does not contain the datastore you specified in vm spec for vmx path and virtual disks paths.