I am experimenting with the VMWare web services SDK. When looking at the PropertyCollector.cs example that they have I can get almost any property except summary.customValues.
So where they have an example like this:
Object[] properties
= getProperties(vmMoRef,new String[] {"name", "runtime.powerState"});
I tried the same thing with the customvalues
Object[] cprops = getProperties(vmMoRef, new String[] { "name", "summary.customValues" });
This doesn't work however (gives "operation not supported" error). I am guessing this is because the first returns a value and the second returns an array of key pairs.
Does anyone have an example of retrieving customValues?
My real goal is to eventually return name and customValues (which we preload with what type of apps the servers are, etc) so I can do custom sorting and stats for application tiers.
Thanks
There seems to be a typo in the property name specified by you. The property name is "customValue" and not "customValues". Try the sample code by specifying "summary.customValue". You will then be required to modify the sample code further to parse the retrieved values.
Hope this helps!
Neha
This is the point I am at now. You have 3 values for each customValue (key, name, value). I can return the keys just fine, but I am having a little trouble getting back the values themselves. I think this is supposed to be a dynamicProperty, but the code commented out below will crash because object is not set to an instance of an object - which sounds to me like it is null.
Is this the proper way to get the values?
Again my goal is to be able to come back with a list with the name and values from summary.customvalue for each VM I am looking at so that I can sort them by the values.
Again the code is based on the PropertyCollector.cs that is in the SDK.
Thanks
Object[] cprops = getProperties(vmMoRef, new String[] { "name", "summary.customValue" });
CustomFieldValue[] cfv = (CustomFieldValue[])cprops[1];
if (cfv != null)
{
for (int ic = 0; ic < cfv.Length; ++ic)
{
int euc = cfv[ic].key;
// DynamicProperty[] cfvDP = cfv[ic].dynamicProperty;
// string dv = (string)cfvDP.GetValue(euc);
// Console.WriteLine("String val: " + dv);
Console.WriteLine("String key : " + euc);
}
}
The field value isn't a DynamicProperty. Instead, you have to cast the CustomFieldValue down to a CustomFieldStringValue object and get the value
from that.
Example: (Java, sorry not a C# guy):
CustomFieldValue[] cfs = ... if (cfs != null) { for (CustomFieldValue cf : cfs) { if (cf instanceof CustomFieldStringValue) { CustomFieldStringValue cfsv = (CustomFieldStringValue) cf; System.out.println(" CustomFieldValue " + cfsv.getKey() + " = '" + cfsv.getValue() + "'"); } else { System.out.println(" CustomFieldValue " + cf.getKey() + "??"); } } }