VMware {code} Community
PritamMoodbidri
Contributor
Contributor

Cannot create VM with vCenter

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:

        final Folder vmFolder = datacenter.getVmFolder();
        final Task task = vmFolder.createVM_Task(vmSpec, resourcePool, host);
and the datacenter belongs to the HostSystem. The problem I see is that, if I directly connect to the ESX server the HostSystem is the ESX server and this works. But, when I connect to the vCenter, the HostSystem address is shown as the vCenter one, but it still is the HostSystem under the vCenter which I find if I go find the child entities under vCenter.
The error I see in case of the vCenter server is 'Invalid datastore path '[<data_store>]'. I checked the paths that is being created in the code is correct, as it works in case of ESX. Please let me know if I am missing something here.
Thanks.
-Pritam
Reply
0 Kudos
10 Replies
stripeyfish
Contributor
Contributor

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"

Reply
0 Kudos
pAntonenko
Contributor
Contributor

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.

Reply
0 Kudos
hpinzaghi
Contributor
Contributor

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

Reply
0 Kudos
pAntonenko
Contributor
Contributor

>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.

Reply
0 Kudos
hpinzaghi
Contributor
Contributor

Exception: com.vmware.vim25.InvalidDatastorePath

are you sure [DatastoreName] vmName/vmName.vmx exist?

Reply
0 Kudos
pAntonenko
Contributor
Contributor

Yes, because when I have connected to EXS vm has the same path:
> [DatastoreName] vmName/vmName.vmx
and everything works fine.
Reply
0 Kudos
hpinzaghi
Contributor
Contributor

first you sure datastore (ManagedEntity)‘s name is DatastoreName

and you can try this path [DatastoreName] vmName1/vmName1.vmx

Reply
0 Kudos
pAntonenko
Contributor
Contributor

Yes, I am sure that datastore‘s name is DatastoreName.
When I use connection with ESX the datastore's name is the same.
Reply
0 Kudos
jirma
Contributor
Contributor

Has this issue been resolved? I think it is a bug of vSphere SDK, do you know the bug id? Thanks in advance!

Reply
0 Kudos
ABar
Contributor
Contributor

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.

Reply
0 Kudos