VMware {code} Community
ChanKaiShi
Enthusiast
Enthusiast
Jump to solution

What do I do with ManagedObjectReference, how do I cast it to specific type?

I read through documentation but still did not figure out what ManagedObjectReference does and how to work with it. Example is below (c#)

I have Vmware object called item. item.Runtime.Host returns ManagedObjectReference of type HostSystem. But how do I access properties of that object?

(HostSystem)item.Runtime.Host is not valid cast, how I access properties for HostSystem in this case?

0 Kudos
1 Solution

Accepted Solutions
tos2k
Expert
Expert
Jump to solution

Hi!

Let me give you a brief introduction to the VimSdk:

The VimSdk is basically a wrapper. That wrapper can be used to access a webservice. The webservice is provided by an ESX host or a VirtualCenter server.

What the VimSdk basically contains are a lot of function calls, operations, to these webservices (ESX / VC).

A ManagedObjectReference (MOR) is nothing more than a typed id (string) to a entity (host, VM, datastore...) on an ESX or in VC, unique per VC instance.

VimSdk does not provide real entity objects such as HostSystem, VirtualMachine aso. These objects, provided by the VimSdk are, basically, lists of MOR with a few details/some info. But you can not call any operations on these objects. For C# there is a framework, I think it is this one http://sourceforge.net/projects/vitfordotnet/ (unsure), that (possibly) gives you "better" entity objects.

So, to read the inventory of VC/ESX, you create a PropertySpec (specification) that is send to the VC/ESX. This contains a specification for all values that you want to receive. You can, f.i. specify that you want to recieve data for a whole datacenter, or even just info for one specific VM. Each property spec can be set to retrieve all members of an entity, and if you do so, requesting a VM will return a VM with all related info and references from it to other entities.

When you finally have the entity references (MOR) you just pass them to calls to the webservice as input argument. You can not call functions/ops on the entities itself, but use the MORs to point a task to the entity.

To have a first look it may be worth to call https://<vc/esx>/mob - the ManagedObjectBrowser. Here you really see what the VimSdk is all about.

Tos2k

View solution in original post

0 Kudos
6 Replies
tos2k
Expert
Expert
Jump to solution

Hi!

Let me give you a brief introduction to the VimSdk:

The VimSdk is basically a wrapper. That wrapper can be used to access a webservice. The webservice is provided by an ESX host or a VirtualCenter server.

What the VimSdk basically contains are a lot of function calls, operations, to these webservices (ESX / VC).

A ManagedObjectReference (MOR) is nothing more than a typed id (string) to a entity (host, VM, datastore...) on an ESX or in VC, unique per VC instance.

VimSdk does not provide real entity objects such as HostSystem, VirtualMachine aso. These objects, provided by the VimSdk are, basically, lists of MOR with a few details/some info. But you can not call any operations on these objects. For C# there is a framework, I think it is this one http://sourceforge.net/projects/vitfordotnet/ (unsure), that (possibly) gives you "better" entity objects.

So, to read the inventory of VC/ESX, you create a PropertySpec (specification) that is send to the VC/ESX. This contains a specification for all values that you want to receive. You can, f.i. specify that you want to recieve data for a whole datacenter, or even just info for one specific VM. Each property spec can be set to retrieve all members of an entity, and if you do so, requesting a VM will return a VM with all related info and references from it to other entities.

When you finally have the entity references (MOR) you just pass them to calls to the webservice as input argument. You can not call functions/ops on the entities itself, but use the MORs to point a task to the entity.

To have a first look it may be worth to call https://<vc/esx>/mob - the ManagedObjectBrowser. Here you really see what the VimSdk is all about.

Tos2k

0 Kudos
ChanKaiShi
Enthusiast
Enthusiast
Jump to solution

Thanks,

I'm wondering how API server works if your request to retrieve real-time performance data out of VC. Does it actually go to individual host and retrieve that information or it's relies on data which is already populated in database. So basically if I try to find top 10 hosts by CPU utilization, do I have to query all of hosts individually and pull that information out in real-time or can rely on API to have those values already available in database.

0 Kudos
Girishbmc
Contributor
Contributor
Jump to solution

Hi,

From this explaination it is pretty much clear that MOR id is unique per VC. So it might be same on two VC. My question is how this id get generated? I mean, if i created managed Object with same name on 2 VC, dose MOR id will be same on both VC? for example resourcepool with name"xyz" on each VC.

Girish

0 Kudos
tos2k
Expert
Expert
Jump to solution

Hi!

I have not been working with performance data so long, so I just can recommend what I think, not what my experiences are.

As both, VC and ESX provide performance data it may just depend on your (coding) preference if you pull them from the hosts directly or from VC. Another question is possibly how "real time" you need the data. VC may have a little delay as it first has to fetch the data from all the hosts.

On the other handside I am unsure if VC has the performance data in its own database, or if it pulls it for you directly from the host.

Tos2k

p.s. please open a new thread when changing the topic

0 Kudos
tos2k
Expert
Expert
Jump to solution

Hi!

So it might be same on two VC.

yes

My question is how this id get generated?

I dont know. I think the id is build up from a type-id (vm, datastore...) and a increasing counter. Afaik this is managed internally by ESX/VC and not worth the effort to create two f.i. VMs with same id on different VC instances. The only way to "change" the id of f.i. a VM is to register/unregister it, which results in increasing the VM counter.

if i created managed Object with same name on 2 VC, dose MOR id will be same on both VC?

Consider the name being completely independent to the id of an entity! So, no.

In fact, when you look on two different ESX hosts, the id for its (only one, default) datacenter is same. I am assuming the same for all other entities. The entity ids from ESX are not same to the ids in VC, which is logical as VC maintains several ESX host in general, and so has to create new entity ids (within the VC scope).

Tos2k

p.s. please open a new thread when changing the topic

0 Kudos
nikhilxp64
Enthusiast
Enthusiast
Jump to solution

You mentioned that with the web services SDK it is not possible to call any methods from the MOR. But what about with Vim.dll that comes with the power shell CLI SDK?

What is the difference between the two? Both namespaces for instance have a "VirtualMachine" type. And from what digging I've done there are many more recommendations to using the Vim.dll - why is that? Isn't the Web Services SDK the newest and most comprehensive of the lot?

0 Kudos