ManagedObjectReference vs ManagedObject

One of the most common confusions that a newcomer has while learning vSphere API is the ManagedObjectReference, a.k.a MOR. If you read the API Reference, you will find a lot of them. Recently there was a question poping in the open source VIJava API forum. So I think it is worth explaining it here.

There are two major types in the vSphere API: managed object types are for these objects on the server side only; and data object types for properties, parameters, and results, which can be send back and forth between client and server. The MOR is a data object type, but used to represent managed objects living on server side. If you are familiar with C/C++ programming, you can think of it as pointer in some sense. Even better, think of it as a combination of table and primary key in relational database. I will explain it more soon.

Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.

The MOR has two properties: type and val, both are strings. The reason for it having type is that there are close to 100 managed object types but only one MOR for all of them. To distinguish them, type is therefore used and its value is limited to available types which are 93 in vSphere 4.1.

The val is the unique identifier for a managed object within a target server. For the same managed object, say a virtual machine, the val can be different when you get it from an ESX/ESXi or the vCenter that manages the ESX/ESXi. Now, let’s get back to the relational database analog just mentioned, the type is the “table” and val is the “primary key.”

Too abstract? Let’s take a look at a sample. A MOR representing a virtual machine may look like this:

type: VirtualMachine
val: vm-820

Once we are clear with MOR, let’s take a look at the ManagedObject. To your surprise, there isn’t a managed object type called ManagedObject in vSphere API reference. As a side story, I told one of my colleagues about this in a meeting and his response was, “I can’t believe it! I got to look it up and show you.” He never gets back to me afterwards.

If you use VI Java API, you do see a type/class ManagedObject which packs quite some code. It’s super class for every managed object types like HostSystem, VirtualMachine, etc. The main reason I added it to the VI Java API is for logical completeness of the object model. When logical, a nice object model comes naturally. From the implementation perspective, it does pull up much code for re-use across different subclasses.

With ManagedObject and its subtypes in VI Java API, you will have objects to work with and write much less code. Even nicer, you have all the typing in place. Before you can have a MOR object pointing to a virtual machine or a host, you mix them up and the compiler won’t catch the mistake. In VI Java API, there are VirtualMachine and HostSystem objects and you simply cannot confuse them or the compiler won’t let you go.

I am sure you all want the benefits of using VI Java API, but still wonder if there is a big performance difference between using MOR and ManagedObject (mainly its subtypes). In theory, there is a difference; in practice, you won’t notice any difference caused by this because the ManagedObject is a VERY thin layer. In fact, you will see 10 times performance boost using VI Java 2.0 because of the new Web Service engine I wrote from scratch.

Well, by this far I hope you understand well the MOR and ManagedObject. When using VI Java API, however, please avoid MOR as much as possible. Instead, use ManagedObject and its subtypes.

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

20 Comments

  1. Posted June 26, 2011 at 6:41 am | Permalink

    Hi Steve,

    could you explain this in a more practical manner also for a powercli user?
    I realy appreciate your effort. Thank you

    regards

    Andreas

  2. Posted June 26, 2011 at 11:35 am | Permalink

    Hi Andreas,

    A great question. PowerCLI has a different object model that is similar to VI Perl. The model has “View” which is close to the “ManagedObject” in VI Java API, but not the same. The “View” does not have subtypes as does ManagedObject in VI Java API, therefore you cannot achieve type safe there. Also, the “View,” once created, retrieves and keeps a local cache of all properties of a managed object, which could be a big waste if you are interested in only one or few of them.

    Hope it helps. Please let me know if you have more questions.

    -Steve

  3. Posted June 27, 2011 at 6:20 am | Permalink

    Hi Steve,

    thanks for your explanation. I try to think about this. Maby one or more questions will rise up :) I also read your Demystifying 3 “View”s from VMware and WPowerCLI Mastery, Volume 2W from winternals.com

    Thanks

    regards

    Andreas

  4. Thulasinathan Kandasamy (Tulsi)
    Posted July 22, 2011 at 10:36 am | Permalink

    Hi Steve,

    On a different note.

    I don’t see any VI Java release after 2010-08-26. Since vCenter5.0 is released now, will there be any new release in VI Java? I presume that the existing version will work great with vCenter5.0 as well.

    Regards,
    Tulsi

  5. Posted July 22, 2011 at 11:21 am | Permalink

    Hi Tulsi,

    The existing vijava 2.1 should work with vCenter 5 as it is but no access to new features. A new version of vijava will be released after vSphere 5 GAs. Stay tuned.

    Steve

  6. Thulasinathan Kandasamy (Tulsi)
    Posted July 25, 2011 at 3:46 am | Permalink

    Thank you so much Steve. Sure.

    Regards,
    Tulsi

  7. Tejaswi
    Posted January 1, 2013 at 11:35 pm | Permalink

    hey!plz give 1 java class wich fetches all vm from the vcenter,since i am a new commer,give some solutions,or link for it..

  8. Posted January 2, 2013 at 3:13 am | Permalink

    Check out the InventoryNavigator class that does exactly what you wanted and more. It is used in many samples in vijava API.
    Steve

  9. Tejaswi
    Posted January 2, 2013 at 5:01 am | Permalink

    thanx!!can you give me its link?
    am unable to find InventoryNavigator

  10. Tejaswi
    Posted January 2, 2013 at 5:24 am | Permalink

    yes,got it.. thanx!!

  11. ap
    Posted July 4, 2013 at 4:18 am | Permalink

    Hi Steve,

    Is there a way to create custom managed objects using vi java?

  12. Posted July 9, 2013 at 4:06 pm | Permalink

    Managed objects, by definition, are ONLY available on the server side. The managed object types in vijava are essentially wrapping proxy for these managed objects on the server side. You can create new managed object types in vijava, but no real managed objects on server side. Hope it helps.

    Steve

  13. ap
    Posted July 10, 2013 at 1:04 am | Permalink

    Hey Steve,

    Thanks for the response.

    And if my understanding is correct, if we can create new managed object types in vijava, then can they be used to be shown in vSphere web-client as an custom inventory object?

  14. Posted July 10, 2013 at 1:10 am | Permalink

    You are very welcome AP,

    I wish what you wished is true. It’s unfortunately not the case.

    Steve

  15. Abhishek
    Posted September 17, 2014 at 12:27 am | Permalink

    I am using VMwareExsi APIs that is vijava sdk for accessing some of the VMs which are running in the hypervisor. I am trying to get list of all processes running in one of the Vms. I have GuestProcessManager instance with me, and I am calling GuestProcessManager .listProcessesInGuest(GuestAuthentication gauth,pids). As evident ,gauth is mandatory parameter for the method.But I am unable to get GuestAuthentication object . How can I retrieve it ?

  16. Posted September 17, 2014 at 10:39 am | Permalink

    There are a couple of posts and samples on the blog. You want to search for them.

    Steve

  17. Abhi
    Posted September 18, 2014 at 12:45 am | Permalink

    Folder rootFolder = si.getRootFolder();

    ManagedEntity[] mes = new InventoryNavigator(rootFolder)

    .searchManagedEntities(“VirtualMachine”);

    NamePasswordAuthentication auth = null;

    auth = new NamePasswordAuthentication();

    String username = “xxx”;

    String password = “xxxxxxx”;

    long[] pids=null;

    auth.setUsername(username);

    auth.setPassword(password);

    auth.setInteractiveSession(true);

    GuestProcessInfo[] processInfo=si.getGuestOperationsManager().getProcessManager((VirtualMachine)mes[1]).listProcessesInGuest(auth,pids);

    What am I getting is :Exception caused:::VI SDK invoke exception:com.vmware.vim25.GuestOperationsUnavailable.

    Any help ???

    If I set interactivesession to false , exception message changes to Exception caused:::VI SDK invoke exception:com.vmware.vim25.GuestComponentsOutOfDate . I am using vijava5.5 .jar for development .

  18. Abhishek
    Posted September 18, 2014 at 9:11 am | Permalink

    Yes Steve, I have followed some blogs.
    Here is my approach.
    —————————————————–
    Folder rootFolder = si.getRootFolder();

    ManagedEntity[] mes = new InventoryNavigator(rootFolder)
    .searchManagedEntities(“VirtualMachine”);
    NamePasswordAuthentication auth = null;
    auth = new NamePasswordAuthentication();
    String username = “xxx”;
    String password = “xxxxxxx”;
    long[] pids=null;
    auth.setUsername(username);
    auth.setPassword(password);
    auth.setInteractiveSession(true);
    GuestProcessInfo[] processInfo=si.getGuestOperationsManager().getProcessManager((VirtualMachine)mes[1]).listProcessesInGuest(auth,pids);

    What am I getting is :Exception caused:::VI SDK invoke exception:com.vmware.vim25.GuestOperationsUnavailable.
    Any help ???

    If I set interactivesession to false , exception message changes to Exception caused:::VI SDK invoke exception:com.vmware.vim25.GuestComponentsOutOfDate .

    I am using vijava5.5 .jar for development .

  19. Abhishek
    Posted September 18, 2014 at 9:13 am | Permalink

    GuestProcessInfo[] processInfo=si.getGuestOperationsManager().getProcessManager((VirtualMachine)mes[1]).listProcessesInGuest(auth,pids);

    The above code segment wasn’t pasted properly in earlier comment.

  20. Abhishek
    Posted September 18, 2014 at 9:15 am | Permalink

    GuestProcessInfo[] processInfo=
    si.getGuestOperationsManager().
    getProcessManager((VirtualMachine)mes[1]).listProcessesInGuest(auth,pids);

8 Trackbacks

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>

  • NEED HELP?


    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.