I'm using the Java webservices api to build out a set of commands for Java Virtualbox. One of the things that I am stuck on is disabling a Network Adapter on a particular Guest VM. Basically virtually unplugging the network cable.
When I used VboxManage.exe, I could call the command VBoxManage.exe controlvm sGuestVMName setlinkstate[adapter ID] off
Now that I'm using the Java WebServices API this type of command is not so easy to define... At least for me...
Here's my code...
Code: Select all
public void setLinkState(VirtualBoxManager oJavaVirtualBoxMgr, IVirtualBox oVirtualBoxInstance, String sVMName,String linkState, int iAdapterID){
ISession oSession = null;
IConsole oConsole = null;
IMachine oMachine = null;
INetworkAdapter oNetwork = null;
try{
oMachine = oVirtualBoxInstance.findMachine(sVMName);
oSession = oJavaVirtualBoxMgr.getSessionObject();
oMachine.lockMachine(oSession, LockType.Shared);
oNetwork = oMachine.getNetworkAdapter();[b] <---- Here is where I'm stuck... Trying to define the iAdapterID which is an int to the long that is required for Slot???? Not sure[/b]
if (linkState.equals("On")){
oNetwork.setCableConnected(true);[b] <---- Also I'm not sure if this works the way I hope it does.. Meaning will it work like "setlinkstate" in VboxManage.exe[/b]
}else{
oNetwork.setCableConnected(false);
}
oSession.unlockMachine();
}catch (VBoxException e)
{
e.printStackTrace();
}
}
Any insight on this would help me immensely..
Thanks
Bill