I am familiar with using the VMware VIM API in C# using the VMware.Vim.dll provided in the PowerCLI. Now I want to be able to program with this API using Java, but I can't find an equivalent to it. The com.vmware.vim.jar in the vSphere SDK doesn't seem to have all of the classes that are mentioned in the API reference here:
http://www.vmware.com/support/developer/vc-sdk/
Specifically, in Java I can't figure out how to get a VirtualMachine instance. In C#, I can get all virtual machines on a stand alone hypervisor by doing the following:
String serviceUrl = "https://192.168.1.100/sdk/vimService";
String username = "root";
String password = "MyPassword";
VimClient client = new VimClient();
client.Connect(serviceUrl);
client.Login(username, password);
var virtualMachines = client.FindEntityViews(typeof(VirtualMachine), client.ServiceContent.RootFolder, null, null).OfType<VirtualMachine>();
How can I get this using Java?
Using VMware Infrastructure (vSphere) Java API i.e vijava below code works to find all VM's in inventory.
String serviceUrl = "https://Your IP Address/sdk";
String username = "root";
String password = "MyPassword";
ServiceInstance si = new ServiceInstance(new URL(serviceUrl), username , password , true);
Folder rootFolder = si.getRootFolder();
ManagedEntity[] entities = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");
for (ManagedEntity e : entities) {
vm = (VirtualMachine) e;
System.out.println("vm=" + vm.getName());
}
OR
http://sourceforge.net/p/vijava/discussion/826592/thread/a6c44685#5b30 ---in cluster environment