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)

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.

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.

This entry was posted in vSphere API and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Yacin
    Posted April 15, 2014 at 10:01 am | Permalink


    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. Posted April 15, 2014 at 12:53 pm | Permalink

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

    Good luck,


Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.