Hi all,
I'm playing around with TraversalSpec, PropertySpec and PropertyFilterSpec to get a hierarchical view of a VirtualCenter. So far everything works fine, except I am unable to get the properties of a Datastore. I've seen lots of examples both on this forum and in the documentation, but none has yielded any results. Has anyone got a working example of that?
I do not need datastores as a propertySet of let's say Datacenter, I want the full propSet of a Datastore. I can post some examples of my Traversal and Prop spec, but any example from the discussion forum will do. None of them are able to get the PropSet of a datastore.
Please prove me wrong
best regards,
Deda
Edit:
I can not find the datastore anywhere in the VI SDK API diagrams, that show the hierarchy. Is there anything special about the datastores? When browsing the hierarchy using the MOB I do see the datastores as expected and the Reference Guide seems to back this...
Always best to include the example of where what you are trying to do.
Here's another way of putting it:
A PropSpec, that works for me may look like this:
PropertySpec\[] pspecs = new PropertySpec[] \{ new PropertySpec() };
pspecs[0].all = true;
pspecs[0].type = "VirtualMachine";
As soon as I change the type to "datastore" I get a SOAP exception.
PropertySpec\[] pspecs = new PropertySpec[] \{ new PropertySpec() };
pspecs[0].all = true;
pspecs[0].type = "datastore";
I did this without any TraversalSpecs.
It just demonstrates, that, when type is "VirtualMachine" I get 0 objects (which is OK, since I did not specify a TraversalSpec).
When the type is "datastore" I get a SOAP exception saying:
"\n \n "
So I can only conclude, that "datastore" can not be used as a type with PropSpec. This goes against the documentation which says nothing about not using "datastore" as a type.
My goal is to retrieve all datastore managed objects and their full PropSet as can be seen in the MOB.
OK... disregard what I just wrote... will put up an example shortly. This one is an obvious typo. Sorry!
Message was edited by:
deda
One thing that's special about datastores is that they don't extend ManagedEntity which means they don't have a "parent" property and which means they're not nodes in the heirarchy. Maybe your TraversalSpec doesn't take this into account.
Marc
OK.. I am expecting the following function to return (among other stuff) datastore objects:
private static PropertyFilterSpec BuildPropertyFilterSpec(ServiceContent sc)
{
// Navigate from ComputeResource to Host
TraversalSpec cr2hTS = new TraversalSpec();
cr2hTS.type = "ComputeResource";
cr2hTS.skip = false;
cr2hTS.path = "host";
// Navigate from ComputeResource to Datastore
TraversalSpec cr2dsTS = new TraversalSpec();
cr2dsTS.type = "ComputeResource";
cr2dsTS.skip = false;
cr2dsTS.path = "datastore";
TraversalSpec ccr2hTS = new TraversalSpec();
ccr2hTS.type = "ClusterComputeResource";
ccr2hTS.skip = false;
ccr2hTS.path = "host";
// Navigate from ClusterComputeResource to Datastore
TraversalSpec ccr2crTS = new TraversalSpec();
ccr2crTS.type = "ClusterComputeResource";
ccr2crTS.skip = false;
ccr2crTS.path = "datastore";
// Navigate from Datacenter to hostFolder
TraversalSpec dc2hTS = new TraversalSpec();
dc2hTS.type = "Datacenter";
dc2hTS.skip = false;
dc2hTS.path = "hostFolder";
dc2hTS.selectSet = new SelectionSpec[] \{ new SelectionSpec() };
dc2hTS.selectSet[0].name = "traverseChild";
// Navigate from Datacenter to vmFolder
TraversalSpec dc2vmTS = new TraversalSpec();
dc2vmTS.type = "Datacenter";
dc2vmTS.skip = false;
dc2vmTS.path = "vmFolder";
dc2vmTS.selectSet = new SelectionSpec[] \{ new SelectionSpec() };
dc2vmTS.selectSet[0].name = "traverseChild";
// Navigate from Datacenter to datastore
TraversalSpec dc2dsTS = new TraversalSpec();
dc2dsTS.type = "Datacenter";
dc2dsTS.skip = false;
dc2dsTS.path = "datastore";
dc2dsTS.selectSet = new SelectionSpec[] \{ new SelectionSpec() };
dc2dsTS.selectSet[0].name = "traverseChild";
// Navigate from Folder to childEntity
TraversalSpec traverseChild = new TraversalSpec();
traverseChild.type = "Folder";
traverseChild.skip = false;
traverseChild.path = "childEntity";
traverseChild.name = "traverseChild";
traverseChild.selectSet = new SelectionSpec[]{new SelectionSpec(),
dc2vmTS,
dc2hTS,
dc2dsTS,
cr2hTS,
ccr2hTS,
cr2dsTS,
ccr2crTS
};
traverseChild.selectSet[0].name = traverseChild.name;
ObjectSpec os = new ObjectSpec();
os.obj = sc.rootFolder;
os.skip = true;
os.selectSet = new SelectionSpec[] \{ traverseChild };
PropertySpec\[] pspecs = new PropertySpec[] \{ new PropertySpec() };
pspecs[0].all = true;
pspecs[0].allSpecified = true;
pspecs[0].type = "ManagedEntity";
PropertyFilterSpec spec = new PropertyFilterSpec();
spec.objectSet = new ObjectSpec[] \{ os };
spec.propSet = pspecs;
return spec;
}
Why i expect this to get the datastores for me is:
1. I have several TraversalSpecs instructing the traversal to a datastore from either ComputeResource, ClusterComputeResource or Datacenter.
2. Datastore is a ManagedEntity.
This works fine, except I am unable to get the datastore objects.
Thanks and sorry for the many posts .
He's right, deda.
Both HostSystem and Datastore are managed OBJECTS, but they are not both ManagedEntity objects... Check the guide VMWare SDK reference guide - http://pubs.vmware.com/vi301/sdk/ReferenceGuide/index.html ... HostSystem extends ManagedEntity, while Datastore does not. From the description of ManagedEntity: "ManagedEntity is an abstract base type for all managed objects present in the inventory tree. The base type provides common functionality for traversing the tree structure, as well as health monitoring and other basic functions."
In other words, because Datastore isn't a ManagedEntity, you're not going to find it by traversing the inventory tree. I ran into the exact same situation that you're dealing with. To resolve it, I wrote a routine that finds all Datacenter objects in the tree, and and returns the contents of the "datastore" property of each Datacenter.
The documentation really isn't clear on this - I don't know why Datastore isn't considered the same as other managed objects.
I see... i did not yet see your post when i posted that DS is a ME.
Thanks everybody.
Following your comments i was able to come up with this code change, that functions exactly as i wanted it in the 1st place.
PropertySpec ps1 = new PropertySpec();
ps1.type = "ManagedEntity";
ps1.all = true;
ps1.allSpecified = true;
PropertySpec ps2 = new PropertySpec();
ps2.type = "Datastore";
ps2.all = true;
ps2.allSpecified = true;
PropertySpec\[] pspecs = new PropertySpec[] \{ ps1, ps2 };
There are no parent references in the datastore objects, but that can be deducted from other objects, that have a datastore[] property.
How can we get the details of all the Virtual Machines under each datastore?