VMware {code} Community
cmwalolo
Contributor
Contributor
Jump to solution

Managed Object References

How do I convert Manager Object references to any of the Managed objects as found in the table 5-1 of the vSphere Web Services SDK Programming Guide vSphere Web Services SDK 4.0.

Furthermore I do not see any type definition of those objects like ResourcePool, DataStore in the VimAPI Namespace, event not in the WSDL of the SDK ? Do i need some more DLLS ? I do not find the vSphere API 4.0 Dlls anywhere in the SDK?

Thanks for any help Smiley Happy

Laurent

Reply
0 Kudos
1 Solution

Accepted Solutions
tos2k
Expert
Expert
Jump to solution

Hi!

It depends. To structure disks, a list of disks seems to me to be appropriate. When you pick another MOR, f.e. vm->runtime->host, then you get the hierarchical stuff returned. So you get both, lists, values and links to other branches in the hierarchy tree.

The easiest way to find properties is to browse the hierarchy manually. This is where the ManagedObjectBrowser (MOB) comes in play. You have access to it by typing https:///mob

Tos2k

View solution in original post

Reply
0 Kudos
6 Replies
tos2k
Expert
Expert
Jump to solution

A ManagedObjectReference, MOR, is not a type. Mao, you cant convert it to something else.

What you can du is to use these MORs to ask vCenter/ESX for its properties.

MORs are the nodes of the tree-structured content of VMware infrastructure. The "content", values aso. is connected/linked these nodes.

You have to create traversal specs, to read properties of nodes. Read/search in the forums, and you will find how to do that!

Maybe you start over here: http://communities.vmware.com/message/1172650#1172650

or here: http://communities.vmware.com/message/844274#844274 (good read that one!)

Smiley Wink

Tos2k

cmwalolo
Contributor
Contributor
Jump to solution

Oki, I start to understand all about this. It seems that the documentation is everything but not helpful. I just spent my time to find some objects that could represent those managedobjectreference as they are talking about in the documentation Smiley Happy

I already had a look to those TraversalSpec and other things. I wonder why they return all only arrays, and not a hierarchical structure ? That seems a bit crazy ?

About the properties... I found the properties of a task in the sample:

pSpec.pathSet = new String[] {"info.entity","info.entityName","info.name","info.state","info.cancelled","info.error"};

Is there any place where we can find those properties for each type of object ?

Thank you anyway for your answer;

Laurent

Reply
0 Kudos
tos2k
Expert
Expert
Jump to solution

Hi!

It depends. To structure disks, a list of disks seems to me to be appropriate. When you pick another MOR, f.e. vm->runtime->host, then you get the hierarchical stuff returned. So you get both, lists, values and links to other branches in the hierarchy tree.

The easiest way to find properties is to browse the hierarchy manually. This is where the ManagedObjectBrowser (MOB) comes in play. You have access to it by typing https:///mob

Tos2k

Reply
0 Kudos
cmwalolo
Contributor
Contributor
Jump to solution

Yap, I managed to get all items, and tryed to build the structure from the array.

1) The order of the items is completely a disaster... we cannot build the structure by just enumerating the objects. As child objects can be shown before parent objects. So the structure build has to be done in multiple passes to find all children node by node / level by level.

2) I got some objects, virtual machines that are in pools, where the parent is not the pool. So finally when I did all my stuff, in two passes to create the structure. The VM in pools are not included becaused the parent object is a folder from the VM and Templates View and not the pool from the cluster view. It's annoying in my case I have a VM that is viewable in my cluster view but not viewable in my VM/Templates view.

So maybe the right solution is to load the structure level by level ?

Laurent

Reply
0 Kudos
tos2k
Expert
Expert
Jump to solution

Have a look at the documentation: http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/visdk25programmingguide.pdf

page 74 shows the main structure, and the two main branches which relate VMs to a datacenter (hostFolder, vmFolder). That is kinda strange for me at least. I mean, do we really need two types of folders? Why two, why isnt one enough, and we just filter items like hosts, templates... I think there are historical reasons influencing the design Smiley Wink

VMs should be visible all time, but templates will be visible just in the template view.

Remember that you can create recursive traversal specs, that indeed lets you pick all the needed data in one ride. But take care, for bigger environments this can take time, and you finally have to sit down, and choose the essential data pieces...

Tos2k

Reply
0 Kudos
cmwalolo
Contributor
Contributor
Jump to solution

I tried that type of code. Here is a piece of code below to see the logic.

List<ObjectContent> objs = cb.GetContainerContents(_service, _sic, datacenterRef, null);

This is mainly what it returns from ObjectContent[http://] ocary =_service.RetrieveProperties(_sic.propertyCollector, new PropertyFilterSpec[|http://] ocary =_service.RetrieveProperties(_sic.propertyCollector, new PropertyFilterSpec[] );

Once I got that array, I can not use the parent property to recreate the structure. VM that are in pools have as parent the folder of the VM/Templates view. Initially i created a notFound list of objects. Then I try as much as I can to put each item in his parent object. In my case I have a VirtualMachine that i cannot put into the structure as it is listed in a pool of my cluster view, but is not listed in the VM/Templates view. So I don't see the meaning of doing those traversalSpec if you finally cannot recreate the structure, or I'm just missing something Smiley Happy

By the way, I cannot even find back a resourcePool using : service.FindByInventoryPath(sic.searchIndex, datacenterName/host/cluster/poolName); it returns null everytime.

public Structure GetStructure(string dataCenter, string[] args)

{

List<Structure> notFound = new List<Structure>();

Structure structure = new Structure();

cb = AppUtil.AppUtil.initialize("TaskList", args);

cb.connect();

service = cb.getConnection().service;

sic = cb.getConnection().sic;

ManagedObjectReference datacenterRef = service.FindByInventoryPath(sic.searchIndex, dataCenter);

if (datacenterRef == null)

{

throw new Exception("The specified datacenter is not found");

}

structure.Id = datacenterRef.Value;

structure.Name = dataCenter;

List<ObjectContent> objs = cb.GetContainerContents(_service, _sic, datacenterRef, null);

foreach (ObjectContent content in objs)

{

Structure child = new Structure();

child.Id = content.obj.Value;

child.Name = GetPropertyString(content.propSet, "name");

child.Type = content.obj.type;

ManagedObjectReference parentObj = (ManagedObjectReference) GetProperty(content.propSet, "parent");

Structure parent = FindParent(structure, parentObj.Value);

child.ParentId = parentObj.Value;

if (parent != null)

{

parent.Children.Add(child);

}

else

{

notFound.Add(child);

}

}

while (notFound.Count > 0)

{

bool done = false;

foreach (Structure s in notFound)

{

Structure parent = FindParent(structure, s.ParentId);

if (parent != null)

{

parent.Children.Add(s);

notFound.Remove(s);

done = true;

break;

}

}

if (!done) break;

}

return structure;

}

Reply
0 Kudos