VMware vSphere API is defined by WSDL. As discussed in my previous blog REST or SOAP, Web Services is by nature procedural, and it does not support OO (object oriented). This contributes to the learning curve of vSphere Web Service API which is modeled with OO.
What if you want to find out what properties are supported by a particular managed object type in vSphere API? There was a specific question recently in blog comment: how to get valid/supported property paths like summary.hardware.numNics with HostSystem type.
Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.
Currently there is no systematically way to get this metadata which is not defined in WSDL. You have to manually read through vSphere API Reference.
Since vSphere Java API 1.0 (a.k.a. VI Java API by then), I have manually added a getter method for every property in the Java API. So the metadata is built in vSphere Java API from the beginning. Whenever there is a manual process, it could be error-prone. As much carefully as I liked, I made mistakes with properties ignored in vSphere Java API occasionally. These mistakes have been immediately patched up upon bug reports or self reviewing.
To get exactly what you want programmatically, you have to do something extra with Java reflection API. Let’s pick HostSystem as an example here.
For HostSystem type, you can find getter methods like “getSummary().” For each of these methods, you can extract property name like summary, and the type as return of the method. Note that not every get*() method (zero parameter) has a corresponding property. The getClass(), for instance, is defined with java.lang.Object, therefore not such a getter method we intend. You must ignore it and only count these get*() method inherited from ManagedObject type and below.
If the return type is a subtype of ManagedObject or an array of such a subtype, you must map it back to the ManagedObjectReference type or its array. Why? In vSphere Java API, I’ve converted all the ManagedObjectReference type or array to real managed object types. Now, you got to recover the orginal type.
Further inspecting these property types (all data object types), you can get all the sub-properties with exception of ManagedObjectReference type. In the above sample, you get find the property “summary” of type HostListSummary. You can call reflection API on HostListSummary and find out information you need.
Well, it may not be as easy as it sounds here. We may build an metadata API for vSphere API in the future. Please leave your comment if you also have such a need.