VMware {code} Community
Janani_Shyam
Contributor
Contributor

VI SDK Accessing Data objects

How can we access the Data objects? I want to access the "VmfsDatastoreInfo" data object and go further and access the "HostVmfsVolume" data object? How can we set the traversal and propertySpec for the data objects? I would to know if there are some samples to show the data object traversal.

0 Kudos
1 Reply
ssurana
VMware Employee
VMware Employee

Hi Janani,

To access the Data Objects you need to first fetch the corresponding Managed Object Reference(MOR) from which the Data Object is to be derived.

To get the MOR of an entity the underlying method is to use the RetrieveProperties method of PropertyCollector. For the parameters to this method you need to create a "PropertyFilterSpec".

When you use different languages for the implementation purpose the API/toolkits provides some ready to use library functions that can be directly used to fetch the entity's MOR.

The generic way of doing the same for your specific requirement would be like the code below. This code snippet is in C# but a similar approach can be followed in any language of your choice like Java, Perl & C#. You can find samples for the data object traversal in many of the samples shipped with the sdk bundle.

TraversalSpec computeResourceDatastoreTraversalSpec = new TraversalSpec();

computeResourceDatastoreTraversalSpec.type = "ComputeResource";

computeResourceDatastoreTraversalSpec.name = "computeResourceDatastoreTraversalSpec";

computeResourceDatastoreTraversalSpec.path = "datastore";

computeResourceDatastoreTraversalSpec.skip = false;

TraversalSpec datacenterHostTraversalSpec = new TraversalSpec();

datacenterHostTraversalSpec.type = "Datacenter";

datacenterHostTraversalSpec.name = "datacenterHostTraversalSpec";

datacenterHostTraversalSpec.path = "hostFolder";

datacenterHostTraversalSpec.skip = false;

datacenterHostTraversalSpec.selectSet = new SelectionSpec[] { new SelectionSpec() };

datacenterHostTraversalSpec.selectSet[0].name = "folderTraversalSpec";

TraversalSpec folderTraversalSpec = new TraversalSpec();

folderTraversalSpec.name = "folderTraversalSpec";

folderTraversalSpec.type = "Folder";

folderTraversalSpec.path = "childEntity";

folderTraversalSpec.skip = false;

folderTraversalSpec.selectSet = new SelectionSpec[] { new SelectionSpec(), datacenterHostTraversalSpec, computeResourceDatastoreTraversalSpec };

folderTraversalSpec.selectSet[0].name = "folderTraversalSpec";

PropertySpec[] propSpecArray = new PropertySpec[] { new PropertySpec() };

propSpecArray[0].type = "Datastore";

propSpecArray[0].all = false;

propSpecArray[http://0].pathSet = new String[|http://0].pathSet = new String[] { "info" };

PropertyFilterSpec propFilterSpec = new PropertyFilterSpec();

propFilterSpec.propSet = propSpecArray;

propFilterSpec.objectSet = new ObjectSpec[] { new ObjectSpec() };

propFilterSpec.objectSet[0].obj = sic.rootFolder;

propFilterSpec.objectSet[0].skip = false;

propFilterSpec.objectSet[http://0].selectSet = new SelectionSpec[|http://0].selectSet = new SelectionSpec[] ;

ObjectContent[] ocArray =

service.RetrieveProperties(sic.propertyCollector, new PropertyFilterSpec[] );

foreach (ObjectContent oc in ocArray)

{

DynamicProperty[] pcArray = oc.propSet;

foreach (DynamicProperty d in pcArray)

{

if (d.val is VmfsDatastoreInfo)

{

if (((VmfsDatastoreInfo)d.val).vmfs != null)

{

//here you would be able to access all the properties of HostVmfsVolume

myItemList.Items.Add(((VmfsDatastoreInfo)d.val).vmfs.blockSizeMb);

}

}

}

}

I hope the above helps.

~ Sidharth

0 Kudos