VMware {code} Community
mravivarma
Contributor
Contributor
Jump to solution

Not able to create a VM using this sample java program

Sample program: https://sourceforge.net/p/vijava/code/HEAD/tree/trunk/src/com/vmware/vim25/mo/samples/vm/CreateVM.ja... .

I downloaded VI Java API (2 jars) from https://sourceforge.net/projects/vijava/files/ and added to my build path.

My vSphere vCenter Server version is 6.0.0. I use Java 1.8. Problem is, I am not able to run the sample program successfully. I get the output: "VM could not be created.". This is because result variable (as in the snippet below from the sample program) is not equal to success.

Task task = vmFolder.createVM_Task(vmSpec, rp, null);

String result = task.waitForMe();

Is VI Java API still compatible with vcenter 6.0?

Any help to resolve this problem is greatly appreciated.

Thank you

Reply
0 Kudos
1 Solution

Accepted Solutions
mravivarma
Contributor
Contributor
Jump to solution

Fixed the issue.

In the sample program, ResourcePool is hardcoded to index [0] like below:
ResourcePool rp = (ResourcePool) new InventoryNavigator(dc).searchManagedEntities("ResourcePool")[0];

I found the number of resource pools in my environment, which is 9. All the vms which I manually created belonged to resource pool [6]. I hardcoded number 6 in the above code and it worked.

View solution in original post

Reply
0 Kudos
2 Replies
mravivarma
Contributor
Contributor
Jump to solution

I see this error in the Vsphere client -> Recent tasks window:

1. Target: WDC_ESO_VC05_Haas (which is my datacenter); Status: A component of the virtual machine is not accessible on the host

Reply
0 Kudos
mravivarma
Contributor
Contributor
Jump to solution

Fixed the issue.

In the sample program, ResourcePool is hardcoded to index [0] like below:
ResourcePool rp = (ResourcePool) new InventoryNavigator(dc).searchManagedEntities("ResourcePool")[0];

I found the number of resource pools in my environment, which is 9. All the vms which I manually created belonged to resource pool [6]. I hardcoded number 6 in the above code and it worked.

Reply
0 Kudos