Agaetis VMWare API is just a wrapper of the VIX API (which is a C++ API) in Java. The VIX API of VMWare allows you to control a VMWare Virtual Machine. That means to run, revert, stop, snapshot a VMWare virtual machine. The only problem was that the VIX API is written in C++ and consequently is not directly usable by a Java program. To solve this little gap there is a Java library called JNA . This latter allows to use shared library from your java code. It does the same thing as JNI but it's easier to use.
First, you need to install the vix api on the computer where you want to use the Agaetis VMWare API. To download it please go to http://www.vmware.com/support/developer/vix-api/.
Without this api installed on the computer, the Agaetis VMWare API won't work because it relies heavily on it. If you don't have a vmware account you will need to create one in order to download the VIX API. If you already use VMWare Server 1.x or 2.x or even Workstation, then you know what I'm speaking about. Otherwise, you should know that it's free and really quick to subscribe.
To be able to use all functionalities from the API, you need to
download the jar file and to put it in the classpath of your
application. Here are the link to download it (you can download it
directly from our nexus repository) :
Everything is ready, let's try to see how it works. The API needs to know where is the VIX shared library. So before any calls to the Agaetis API, we need to provide VIX library location to JNA. This location is easy to find if you remember where you installed the VIX library in the second point of this documentation. By default it's located in "/usr/lib/vmware-vix/lib/ for Linux system and in " C:\Program Files\VMWare\VMWare VIX\" for Windows. If in those folders you can find a file called libvixAllProducts.so (Linux) or vix.dll (Windows), then it's the folder you were looking for and that will tell to JNA where the shared libraries are located. It behaves a bit like a classpath for JNA.
You can notice that there are different folders where you can find Vix libraries. All are specific to a VMWare product. If you use a VMWare Server 2 to run the virtual machine you want to connect to, all necessary libraries are in the "VMWARE VIX FOLDER/VIServer-2.0.0/32bit" folder. If you use a VMWare Server 1.0 then they should be in "VMWARE VIX FOLDER/server-1/32bit".
So, to avoid problems of dependency you need to declare the folder in the library path of your system. For instance if you installed the VIX API in "C:\Program Files\VMWare\VMWare Vix\" in a Windows platform, and you want to connect to vm's hosted by VMWare Server 2, then you need to add to the PATH environment variable "C:\Program Files\VMWare\VMWare Vix\VIServer-2.0.0\32bit". If you are under Linux then you should set the LD_LIBRARY_PATH the same way. If this is not done then you can expect some Unsatisfied Link Exception at runtime. If you are under linux you can always create symbolic link if you have such exception.
So before any calls to the Agaetis VMWare API you should set this location by using the static mehod VixLibrary.setLibraryPath() . here is an example :
VixLibrary.setLibraryPath("/usr/lib/vmware-vix/lib/");VixHost vhost = new VixHost();
vhost.setPort(0);
vhost.setHost("https://localhost:8333/sdk");
vhost.setUsername("username");
vhost.setPassword("password");
vhost.setServiceProvider(Vix.ServiceProvider.VMWARE_VI_SERVER);VixHost vhost = new VixHost();
vhost.setPort(902);
vhost.setHost("192.168.0.23");
vhost.setUsername("username");
vhost.setPassword("password");
vhost.setServiceProvider(Vix.ServiceProvider.VMWARE_SERVER); VixVM myVM = vhost.open("[standard] Virtual Machine/Virtual Machine.vmx");VixVM myVM = vhost.open("/home/me/vmware/Virtual Machine/Virtual Machine.vmx");if (myVM.isOn()) { ... }myVM.powerOn();