Home > vSphere API > How to Get ESX Version from vCenter?

How to Get ESX Version from vCenter?

August 16th, 2010 Leave a comment Go to comments

There is a recent question in vSphere(VI) Java API forum about this. On its face, it’s very easy because most people know how to get hold of the version as follows: 

String version = si.getAboutInfo().getVersion();

The si in the above code is the variable of ServiceInstance object. If you have never used the API yet, please try this Getting Started Tutorial which shows how to get your first program running from scratch in 5 minutes

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.

If you are connecting to a vCenter server and try to get the version of a HostSystem the vCenter manages, it’s not so obvious. But it’s definitely doable. Here is the solution assuming you already get hold of the HostSystem object as host variable here: 

String version = host.getConfig().getProduct().getVersion();

Here you know why. First, the aboutInfo is now called product although they are of the same type. Second, it’s hidden within the config property. 

Before taking the code away, I would like to share with you an important tip for better performance. You should consider the following code: 

String version = (String) host.getPropertyByPath(“config.product.version”);

 Or, 

AboutInfo ai = ((AboutInfo) host.getPropertyByPath(“config.product”);
String version = ai.getVersion();

Why? 

Because config object could be huge and it takes time for the vCenter to grab the data and serialize it to XML, and for VI Java API to de-serialize XML back to data object. You can expect getConfig() call take about one second to finish. Most of that time is on vCenter side for grabbing data. So to avoid this, you can just fetch the sub-properties with much faster speed. 

This tip works as well if you connect to ESX directly.

Categories: vSphere API Tags: ,
  1. August 16th, 2010 at 00:12 | #1

    Nice tip Steve. How can I search your blog posts for similar tips on using the SDK? because I don’t see tags on the posts. If you’d tagged this one like sdk-tips or something then it would’ve been great help. Anyways, you and your work rocks! keep us entertained with it :)

  2. August 17th, 2010 at 03:30 | #2

    Sorry, I see the tags now, dunno how I missed them earlier on.

  3. August 17th, 2010 at 15:05 | #3

    Thanks Monis,

    Need your comments as well. Keep them coming! :-)

    -Steve

  4. nikhil
    July 3rd, 2012 at 13:07 | #4

    hi steve…
    i m doing project on managing esxi server and i need different methods defined in vi java api…
    so i will be thankful if you provide me possible methods with its proper syntax

    tanks a lot in advance

  1. No trackbacks yet.