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.
Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.
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.