Quantcast
Channel: VMware Communities : All Content - vSphere Management SDK
Viewing all articles
Browse latest Browse all 1860

Searching for a Managed Entity

$
0
0

Using the VI Java API, I've seen two ways of searching for Managed Entities. For example, if I'm looking for a Virtual Machine, I could do either

ManagedObjectReference mor = new ManagedObjectReference();
mor.setType("VirtualMachine");
mor.set_value(vmname);
VirtualMachine vm = (VirtualMachine) MorUtil.createExactManagedEntity(si.getServerConnection(), mor);// which is the same as 'new VirtualMachine(si.getServerConnection(), mor)' if 'mor' is set up correctly

or

 

VirtualMachine vm = (VirtualMachine) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("VirtualMachine", vmname);

 

 

Which one is faster (it would seem to be the first)? The second seems safer. What are the pros and cons to using each of these  (for example, is there a situation you would use one over the other)?


Viewing all articles
Browse latest Browse all 1860

Trending Articles