2 Replies Latest reply on Jul 26, 2009 7:43 PM by dikang85

    open source VI Java API

    Steve Jin Expert

      I am pleased to tell you that the VI Java API I have developed got company formal approval to be open sourced. Please note that this project is a open source project under BSD license, not a VMware product. Please check out the License.txt file included in the downloadable jar file.

       

      The key benefits of this API are:

      • Enables OO programming with a well defined managed object model

      • Reduces the need to use ManagedObjectReference

      • Hides the complexity of the PropertyCollector

      • Provides necessary utility classes to simplify VI SDK web interfaces

      • Leverages current VI SDK web services interface while keeping it intact

       

       

      The downloadable jar you will find in the download page is very small (264KBcompressed), but includes binary, source and sample code.

       

      To quickly show you how the appications building on top of this API look like, I hereby show you a small sample:

       

      package com.vmware.vim25.mo.samples;

       

      import java.net.URL;

      import com.vmware.vim25.*;

      import com.vmware.vim25.mo.*;

       

      import com.vmware.vim25.mo.util.*;

       

      public class HelloVM

      {

      public static void main(String[] args) throws Exception

      {

      CommandLineParser clp = new

      CommandLineParser(new

      OptionSpec[]{}, args);

       

      String urlStr = "https://esx-server/sdk";

      String username = "username";

      String password = "password";

       

      ServiceInstance si = new ServiceInstance(new URL(urlStr), username, password, true);

      Folder rootFolder = si.getRootFolder();

      VirtualMachine vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine")[0];

      VirtualMachineConfigInfo vminfo = vm.getConfig();

      VirtualMachineCapability vmc = vm.getCapability();

       

      System.out.println("Hello "+ vm.getName());

      System.out.println("GuestOS: " + vminfo.getGuestFullName());

      System.out.println("Multiple snapshot supported: " + vmc.isMultipleSnapshotsSupported());

       

      si.getServerConnection().logout();

       

      }

      }

       

      Compared wtih the similar code directly using VI SDK web services interface, you will find the above sample is much less in LOC, and more importantly much more

      READABLE.

       

      To find out more about this API, you can read two important docs: get started with VI Java API (2 pages) and object model of VI Java API (3 pages) at:

      http://sourceforge.net/docman/?group_id=228007

       

      To download the API package, please go to:

      http://sourceforge.net/project/showfiles.php?group_id=228007

       

      Project home:

      http://sourceforge.net/projects/vijava

       

      I look forward to hearing from you, either bug/feature request/suggestion or anything else. As I said, this project is an open source effort, please feel free to contribute to the community.

       

      -Steve

        • 1. Re: open source VI Java API
          tianxingjian Lurker

           

          I am using VI SDK 2.5. I try to get the value of multiHostSupported from the capability which is a property of* **Servic

           

           

          it seems that it can't be accessed directly from the reference of ServiceInstance ... I tried other ways but does not work?

           

           

          Do you know if there is a way to get it? or if there is simple way in SDK 4.0?

           

           

           

           

           

           

           

           

           

           

           

          • 2. Re: open source VI Java API
            dikang85 Novice

             

            Hi Steve,

             

             

            Thank you for your information.

             

             

             

             

             

            And i tried to run your java sample code, but got the error "Exception in thread "main" java.lang.InstantiationError: com.vmware.vim25.VimPortType" . Can you give me some advices about this?

             

             

             

             

             

            Thanks

             

             

            Dikang