Search code examples
javavirtual-machinevmwarevsphere

VIJAVA: Get exact list of VM's asked for instead of sorting through ALL


Is there any way through vijava to get the exact list of VM's I want whilst also getting their "type info" (e.g. runtime, config, guest objects)? Currently you have to go through InventoryNavigator which grabs all listed VM's and iterates through until it finds the one which matches the name you're interested in. This seems like overkill. Is there anyway I can get the exact VM(s) I'm asking for without first retrieving everything?

String [][] typeInfo = new String[][] {new String[]{"guest", "config", "runtime"}};
ManagedEntity entity = new InventoryNavigator().searchManagedEntity(typeInfo, "hello-world-vm");

In debugging it's been found this single call returns all VM's listed and the API searches through that list to find the one matching the passed name. For performance reasons I'd like to NOT return every listed VM but only the "hello-world-vm".


Solution

  • You should use something unique to locate the VirtualMachine you are looking for like its UUID.

    For example:

    ServiceInstance si = new ServiceInstance(xxx)
    String uuid = "some uuid here"
    VirtualMachine vm = si.searchIndex.findByUuid(null, uuid, true)
    

    This will return only the VM that has the given uuid. The above code is groovy not Java, you would need to use semi colons and the getxxx methods in Java I think (Its been ages since I wrote actual Java)