VMware {code} Community
PsychoQuack
Contributor
Contributor

vmware-vix jna binding

Hello!!

Here is a C/P of a previous mail I sent to the users mailing list of the jna project:

Quote

Hello,

I'm currently trying to write a java binding for the vmware-vix API and

I'm striking against a weird issue. I'm not using the entire API yet but

when I try to powerOn a virtual, I obtain different results. Among those

one:

err: 0 - The operation was successful

err: 16 - The system returned an error. Communication with the virtual machine may have been interrupted

err: 3006 - The virtual machine needs to be powered on

The last one is my favorite:D...

I saw that a Hudson plugin was written but I didn't find the sources,

anyway I don't think that writing the Library binding using jna is a hard

thing to do... below is an example of my implementation:

CODE

public static class VixHandle extends IntegerType {

public static class ByReference extends IntByReference {

public ByReference(){

super();

}

}

public VixHandle.ByReference ByReference = null;

public VixHandle(long v){

super(4);//in vix.h -> typedef int VixHandle;

ByReference = new ByReference();

}

public VixHandle(){

super(4,0);

ByReference = new ByReference();

}

}

And the main method:

CODE

VixHandle hostHandle = new VixHandle();

VixHandle vmHandle = new VixHandle();

IntByReference tmpVM = new IntByReference(vmHandle.intValue());

IntByReference tmpHost = new IntByReference(hostHandle.intValue());

VixHandle jobHandle = VixLibrary.SYNCH_INSTANCE.VixHost_Connect(

VixLibrary.VIX_API_VERSION,

VixLibrary.VIX_SERVICEPROVIDER_VMWARE_SERVER,

null,

904,

null,

null,null,VixLibrary.VIX_INVALID_HANDLE,null,null);

VixError err = VixLibrary.SYNCH_INSTANCE.VixJob_Wait(jobHandle,

VixLibrary.VIX_PROPERTY_JOB_RESULT_HANDLE,

tmpHost,

VixLibrary.VIX_PROPERTY_NONE);

hostHandle.setValue(tmpHost.getValue());

VixLibrary.SYNCH_INSTANCE.Vix_ReleaseHandle(jobHandle);

jobHandle = VixLibrary.SYNCH_INSTANCE.VixVM_Open(hostHandle,

"/home/inria/.vmware/Machines/Machine1/Machine1.vmx",null,null);

err = VixLibrary.SYNCH_INSTANCE.VixJob_Wait(jobHandle,

VixLibrary.VIX_PROPERTY_JOB_RESULT_HANDLE,

tmpVM,

VixLibrary.VIX_PROPERTY_NONE);

vmHandle.setValue(tmpVM.getValue());

VixLibrary.SYNCH_INSTANCE.Vix_ReleaseHandle(jobHandle);

for(int i = 0; i != 100;i++){

jobHandle =

VixLibrary.SYNCH_INSTANCE.VixVM_PowerOn(vmHandle,VixLibrary.VIX_VMPOWEROP_NORMAL,VixLibrary.VIX_INVALID_HANDLE,null,null);

err = VixLibrary.SYNCH_INSTANCE.VixJob_Wait(jobHandle,

VixLibrary.VIX_PROPERTY_NONE);

System.out.println("err: "err" -

"+VixLibrary.SYNCH_INSTANCE.Vix_GetErrorText(err,null));

System.out.println("myJob powerOn :"+jobHandle);

VixLibrary.SYNCH_INSTANCE.Vix_ReleaseHandle(jobHandle);

if(VixError.VIX_SUCCEEDED(err)) break;

}

//seulement si on a allumé la vm

if(VixError.VIX_SUCCEEDED(err)){

for(int i = 15; i != 0; i--){

System.out.println("j'attends");

try {

Thread.currentThread().sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

jobHandle =

VixLibrary.SYNCH_INSTANCE.VixVM_PowerOff(vmHandle,VixLibrary.VIX_VMPOWEROP_NORMAL,null,null);

err = VixLibrary.SYNCH_INSTANCE.VixJob_Wait(jobHandle,

VixLibrary.VIX_PROPERTY_NONE);

System.out.println("err: "err" -

"+VixLibrary.SYNCH_INSTANCE.Vix_GetErrorText(err,null));

System.out.println("myJob powerOff :"+jobHandle);

VixLibrary.SYNCH_INSTANCE.Vix_ReleaseHandle(jobHandle);

}

VixLibrary.SYNCH_INSTANCE.Vix_ReleaseHandle(vmHandle);

VixLibrary.SYNCH_INSTANCE.VixHost_Disconnect(hostHandle);

System.out.println("disconnected");

Ok... I'd like to know if my issue could be tied to the vmware-vix API?

ThX

Guillaume Jean-Michel

Reply
0 Kudos
0 Replies