Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>First question:</strong> You can use the following code to get properties of DataStore. I tested this code on vCenter 5.1</p> <pre><code>public void Test() { var properties = GetProperties( new ManagedObjectReference { type = "Datastore", Value = "&lt;your_datastore_key&gt;" }, new[] {"summary.capacity", "summary.freeSpace", "summary.name"}); } private List&lt;DynamicProperty&gt; GetProperties(ManagedObjectReference objectRef, string[] properties) { var typesAndProperties = new Dictionary&lt;string, string[]&gt; { { objectRef.type, properties } }; var objectContents = RetrieveResults(typesAndProperties, new List&lt;ManagedObjectReference&gt; { objectRef }); return ExtractDynamicProperties(objectRef, objectContents); } private List&lt;ObjectContent&gt; RetrieveResults(Dictionary&lt;string, string[]&gt; typesAndProperties, List&lt;ManagedObjectReference&gt; objectReferences) { var result = new List&lt;ObjectContent&gt;(); var tSpec = new TraversalSpec { path = "view", skip = false }; var oSpec = new ObjectSpec { skip = true, selectSet = new SelectionSpec[] { tSpec } }; oSpec.obj = service.CreateListView(serviceContent.viewManager, objectReferences.ToArray()); tSpec.type = "ListView"; var fSpec = new PropertyFilterSpec { objectSet = new[] { oSpec }, propSet = typesAndProperties.Keys.Select(typeName =&gt; new PropertySpec { type = typeName, pathSet = typesAndProperties[typeName] }).ToArray() }; PropertyFilterSpec[] pfs = { fSpec }; var retrieveResult = service.RetrievePropertiesEx(serviceContent.propertyCollector, pfs, new RetrieveOptions()); if (retrieveResult != null) { result.AddRange(retrieveResult.objects); while (!String.IsNullOrEmpty(retrieveResult.token)) { retrieveResult = service.ContinueRetrievePropertiesEx(serviceContent.propertyCollector, retrieveResult.token); result.AddRange(retrieveResult.objects); } service.DestroyView(oSpec.obj); } return result; } private static List&lt;DynamicProperty&gt; ExtractDynamicProperties(ManagedObjectReference objectRef, IEnumerable&lt;ObjectContent&gt; objectContents) { var result = new List&lt;DynamicProperty&gt;(); foreach (var objectContent in objectContents) { if (objectContent.propSet == null) continue; if (objectContent.obj == null) continue; if (objectContent.obj.type != objectRef.type || objectContent.obj.Value != objectRef.Value) continue; result.AddRange(objectContent.propSet); } return result; } </code></pre> <p><strong>How to run the sample:</strong></p> <ol> <li>Initialize the <code>service</code> by object of <code>VimService</code> class and the <code>serviceContent</code> by object of <code>ServiceContent</code> class.</li> <li>Login to vCenter or ESX using <code>service</code>.</li> <li>Replace <code>&lt;your_datastore_key&gt;</code> with Key of your datastore. You can use the <a href="http://pubs.vmware.com/vsphere-50/index.jsp?topic=/com.vmware.wssdk.pg.doc_50/PG_ChB_Using_MOB.20.1.html" rel="nofollow">Managed Object Browser</a> to find keys of their datastores. To get a description of datastore object, go to following links in MOB: content -> rootFolder -> childEntity -> datastoreFolder -> childEntity. Value of "Managed Object ID" on top of page is correct Key (like <code>datastore-46</code>).</li> </ol> <p><strong>Second question:</strong> Yes, the type of ManagedObjectReference is case sensitive.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload