VMware {code} Community
Mobster
Contributor
Contributor
Jump to solution

Of property, traversal, and object specs!

I have c# code that retrieves various items of inventory, using the usual rigmarole of object, property, and traversal specs etc.

The traversal spec I am using is a fairly "broad" one - it basically includes every time of traversal imaginable in going through the inventory tree. The objective is to basically get all VMs with some associated properties.

One thing that is bugging me now is that if I start the object spec at the moref of the root folder or the vmfolder of a datacenter, everything works fine and I get the morefs to VMs and the properties I want. However, if I start the object spec (objectspec.obj) at the moref of the datacenter itself, then I do not get anything back. Is it even possible to start at a datacenter (not the vmfolder of the datacenter) and get all the VMs therein? I understand that I can get the vmfolder from the datacenter and then get the VMs, and that works fine - the question is whether I can start at the datacenter moref itself.

Any help or comments would be much appreciated.

-- Moby

Reply
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Hi Moby,

Yes, you can start from datacenter itself and then fetch the VMs through the datacenter->vmfolder->VM path. Basically the point is that you can start from any object, provided you get the managed object reference for that object. For example, if you want retrieve VM runtime info, you can set your starting object as datacenter and then drill down all the way to VM through the traversal spec and then fetch the prop. Alternatively, if you have the VM MO R, set the starting point as the VM and then fetch the prop.

There might be some issue in the way you are writing your traversal spec.

Hope this info helps!

- Angela -

View solution in original post

Reply
0 Kudos
6 Replies
admin
Immortal
Immortal
Jump to solution

Hi Moby,

Yes, you can start from datacenter itself and then fetch the VMs through the datacenter->vmfolder->VM path. Basically the point is that you can start from any object, provided you get the managed object reference for that object. For example, if you want retrieve VM runtime info, you can set your starting object as datacenter and then drill down all the way to VM through the traversal spec and then fetch the prop. Alternatively, if you have the VM MO R, set the starting point as the VM and then fetch the prop.

There might be some issue in the way you are writing your traversal spec.

Hope this info helps!

- Angela -

Reply
0 Kudos
Mobster
Contributor
Contributor
Jump to solution

Thanks Angela - it was a wedged traversalspec - works like a charm once I redid the tspec.

Reply
0 Kudos
vpnprasad
Contributor
Contributor
Jump to solution

Hi,

I am trying to understand writing the traversal spec to browse through inventory. Appreciate if you can explain or point me to the appropriate documentation to read and understand. It will be great if you can share your code also.

Thanks,

Prasad

Reply
0 Kudos
Steve_Jin
Expert
Expert
Jump to solution

check out this code of vijava API: http://vijava.svn.sourceforge.net/viewvc/vijava/trunk/src/com/vmware/vim25/mo/util/PropertyCollector...

It has code to build full inventory traversal.

Steve Jin, http://www.doublecloud.org

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
vpnprasad
Contributor
Contributor
Jump to solution

Thanks a lot for your reply. I understood the pattern of writing the traversal spec though I did not logically understand the reason for including all the below selection specs as we go up.

Thanks,
Prasad

Reply
0 Kudos
Steve_Jin
Expert
Expert
Jump to solution

Hi Prasad,

I think you can simplify the traversal spec if you just start from a Datacenter. But I dont think you will  get much by doing that unless you notice a performance problem there.

Steve, http://www.doublecloud.org

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos