Home > vSphere API > ManagedObjectReference vs ManagedObject

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.

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.

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.

Categories: vSphere API Tags: ,
  1. June 26th, 2011 at 06:41 | #1

    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. June 26th, 2011 at 11:35 | #2

    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. June 27th, 2011 at 06:20 | #3

    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)
    July 22nd, 2011 at 10:36 | #4

    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. July 22nd, 2011 at 11:21 | #5

    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)
    July 25th, 2011 at 03:46 | #6

    Thank you so much Steve. Sure.

    Regards,
    Tulsi

  7. Tejaswi
    January 1st, 2013 at 23:35 | #7

    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. January 2nd, 2013 at 03:13 | #8

    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
    January 2nd, 2013 at 05:01 | #9

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

  10. Tejaswi
    January 2nd, 2013 at 05:24 | #10

    yes,got it.. thanx!!

  11. ap
    July 4th, 2013 at 04:18 | #11

    Hi Steve,

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

  12. July 9th, 2013 at 16:06 | #12

    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
    July 10th, 2013 at 01:04 | #13

    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. July 10th, 2013 at 01:10 | #14

    You are very welcome AP,

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

    Steve

  15. Abhishek
    September 17th, 2014 at 00:27 | #15

    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. September 17th, 2014 at 10:39 | #16

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

    Steve

  17. Abhi
    September 18th, 2014 at 00:45 | #17

    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
    September 18th, 2014 at 09:11 | #18

    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
    September 18th, 2014 at 09:13 | #19

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

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

  20. Abhishek
    September 18th, 2014 at 09:15 | #20

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

  1. June 28th, 2011 at 00:02 | #1
  2. July 1st, 2011 at 00:01 | #2
  3. August 16th, 2011 at 00:04 | #3
  4. November 30th, 2011 at 01:05 | #4
  5. January 18th, 2012 at 00:03 | #5
  6. February 28th, 2014 at 11:58 | #6
  7. March 2nd, 2014 at 13:29 | #7
  8. September 18th, 2015 at 03:51 | #8