A Trick With OptionManager in vSphere API
There was recently a question in the open source VI Java API forum regarding the OptionManager. As you may have known, the OptionManager is used to manage key value pairs, for example, the “VMFS3.HardwareAcceleratedLocking” is a key as shown in the code included in the question. Somehow the code to set the key, as shown below, doesn’t work with com.vmware.vim25.InvalidArgument exception.
OptionManager optionmanager = host.getOptionManager(); OptionValue changedValue = new OptionValue; changedValue = new OptionValue(); changedValue.setKey("VMFS3.HardwareAcceleratedLocking"); changedValue.setValue(0); optionmanager.updateOptions(changedValue);
As it turns out, one character change solved the problem. Monsrud who raised the question also figured out the solution – just change parameter to the setValue() method as follows:
Time to learn how to "Google" and manage your VMware and clouds in a fast and secureHTML5 App
The solution seems a little too magical to believe. What happens is that the value in the OptionValue is xsd:anyType, therefore java.lang.Object in Java. When it gets serialized, a type is included. In the case without L, it’s declared as xsd:int; with L, xsd:long. Therefore there is a difference in the SOAP request when you change the type.
Going beyond this particular issue, you may have other similar cases. When you get cases like this, you can try this trick.
Thanks to Monsrud for not only raising the question but also sharing the solution! That is truly a community spirit.