Home > vSphere API > Why Virtual Machine Not Found?

Why Virtual Machine Not Found?

I saw a new bug (Intermittent ManagedObjectNotFound on VirtualMachine.getConf) filed in the open source VI Java API project today:

It looks like sometimes VirtualMachine.getConfig() returns null, but other times it throws:
Caused by: java.lang.RuntimeException: com.vmware.vim25.ManagedObjectNotFound
at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:158)
at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:179)
at com.vmware.vim25.mo.VirtualMachine.getConfig(VirtualMachine.java:55)

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure


As the vSphere API reference points out, the config property could be unset.

The virtual machine configuration is not guaranteed to be available. For example, the configuration information would be unavailable if the server is unable to access the virtual machine files on disk, and is often also unavailable during the initial phases of virtual machine creation.

So it’s expected for you to get null in Java while calling getConfig on a VirtualMachine object due to various reasons.

Still, it’s puzzling to get the ManagedObjectNotFound exception – it means the managed object is not there. Because the PropertyCollector managed object is used to retrieve the config property, there are actually two managed objects involved: the PropertyCollector, and the VirtualMachine of your interest. Which is not found? Because the PropertyCollector is a built-in singleton managed object within a target server either vCenter or ESX, it should be there always. So it’s the VirtualMachine object that is likely not found.

The question then becomes, “why the PropertyCollector cannot find the virtual machine whose ManagedObjectReference exists already?” As questioned in the bug, “this can happen when ESX and vCenter are temporarily out of sync or VMs are found in the ‘Discovered virtual machine’ folder.” I think there is a possibility for the first case. For the second case, the “Discovered virtual machine” folder is just like any other folders even though the system has it as default for VMs added without specifying folder like the following cmd in this article, therefore it shouldn’t make a VM not found.

vmware-cmd -s register “/home/vmware/W2K3 STD SP1/W2K3 STD SP1.vmtx”

Having said that, there is a valid case for a VirtualMachine not found: the VirtualMachine is unregistered from inventory even though it’s not deleted in datastore. On the client side, you can still have a valid VirtualMachine object but it’s no longer referring to a valid virtual machine on the server side. If that happens, throwing exception is consistent not intermittent.

Overall it’s not typical for VirtualMachine object and other ManagedEntity objects because the inventory is relatively stable. However, it can be very common for the Task objects, which remain live only for several minutes. After that, calling any method on them will fail.

While I don’t have a good explanation on the intermittent exception, hearing what goes wrong definitely help improve the Java API. It also helps to find bugs on the core vSphere API.

  1. Yacin
    April 15th, 2014 at 10:01 | #1


    I have a problem concerning an operation I want to do.

    I have my VSphere Tree of VM :

    Folder 1:
    –Folder 2_1:
    —-Folder 3_2:

    What I want is for example to retrieve only the VM of the group and sub-groups of the folder 3_1…

    Does anyone have a solution please ? Because for the moment I have something but this is not very clean and fast (because there is so many VM in the network)…

    // Retrieve a VM of a sub-group
    ManagedEntity me = new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", "VM1");
    // Retrieve the grand parent folder
    ManagedEntity[] met = new InventoryNavigator(me.getParent().getParent()).searchManagedEntities("VirtualMachine");

    Thank you, Yacin.

  2. April 15th, 2014 at 12:53 | #2

    You can use searchManagedEntity to search folder 3_1 with “Folder”. Then use the Folder object to search your VMs.

    Good luck,


  1. No trackbacks yet.