4 Rules for Converting Onyx Generated Code
VMware PM Carter Shanklin (@cshanklin) once gave a great presentation on how to use Onyx with Java development at PEX 2010. I covered it briefly in a previous blog, and left out the “4 rules” hoping Carter would help.
As many of you have already known, Carter moved on to SpringSource division as the PM for tc server. So he has been pretty busy with his transition. With his coverage on both administrator and developer oriented products, he is right on the wave of devops movement. Make sure you follow him at Twitter.
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.
Now let’s get back to his 4 rules of converting Onyx generated code to a language of your choice:
- Create objects when Onyx does, and use the same name.
- Assemble the overall object at the end.
- Bring your own code to looking up IDs.
- Replace Get-View with class methods or static look up code.
The first two rules are relatively easy to understand. Whatever data objects Onyx created, you need corresponding ones in your language say Java. Because data objects contain each other, all the contained data objects should be assembled into the top one.
The last two rules are not that straight forward due to the way Onyx works. At the very high level, Onyx records whatever you do in the vSphere Client as SOAP messages and converts the messages to PowerCLI code (could be other code in the future). The vSphere Client uses ManagedObjectReference objects as IDs whose values are very dynamic depending how you drive the vSphere Client. When you convert these IDs, you want to have your own way to get them. There are several ways to get the IDs in VI Java API. You can use either InventoryNavigator or SeachIndex to look up any managed entity you are interested, or navigate the inventory tree one by one.
The key value offered by Onyx for Java developers is on the data objects which may have hundreds of sub properties and therefore be confusing sometimes. When you have no idea on what values for your parameters, when you get any clueless InvalidRequest exception, it’s high time that you pick up Onyx.
For more of Carter’s presentation, check it out here.