vboxwebsrv sdk and php bindings

This is for discussing general topics about how to use VirtualBox.
Post Reply
mathomp
Posts: 3
Joined: 8. Apr 2010, 17:08
Primary OS: Mac OS X Leopard
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows

vboxwebsrv sdk and php bindings

Post by mathomp »

I have yet another vboxwebsrv question...

So I got everything working. Can list vm's, get their configs, start them and stop them, pause them and save them... but for the life of me I can not figure out how to mount a floppy disk to a running windows vm and have the machine realize that a floppy image has been placed into its floppy drive. Here is the code:

Code: Select all

<?php
require_once('vboxServiceWrappers.php');

//Connect to webservice
$connection = new SoapClient("vboxwebService.wsdl", array('location' => "http://localhost:18083/", 'trace' => 1));

//Logon to webservice
$websessionManager = new IWebsessionManager($connection);

$virtualbox = $websessionManager->logon("null","null");

$newMachine = $virtualbox->findMachine("Windows XP");

$floppyImg = $virtualbox->getFloppyImage("ca7d3782-6c20-4106-a78d-d40b54a00355");
$floppyImg->lockRead();

$newMachine->mountMedium("Floppy Controller", 0, 0, "ca7d3782-6c20-4106-a78d-d40b54a00355", false);
$fff = $newMachine->getMediumAttachment("Floppy Controller", 0, 0);
echo $fff->getMedium()->name . "<br/>";

$medias = $newMachine->getMediumAttachments();

foreach($medias as $ma) {
	echo "=============== <br/>";
	echo "media attach cnt: " . $ma->getController() . "<br/>";
	echo "media attach port: " . $ma->getPort() . "<br/>";
	echo "media attach device: " . $ma->getDevice() . "<br/>";
	echo "media attach type: " . $ma->getType() . "<br/>";
	
	$med = $ma->getMedium();
	if($med->handle != null) {
		echo "med: " . $med->name . "<br/>";
		echo "med: " . $med->getFormat() . "<br/>";
		echo "med: " . $med->getDeviceType() . "<br/>";
		echo "med: " . $med->getType() . "<br/>";
		echo "med: " . $med->getState() . "<br/>";
		echo "med: " . $med->getLocation() . "<br/>";
		echo "med: " . $med->getSize() . "<br/>";
		echo "med: " . $med->getLogicalSize() . "<br/>";
		echo "med: " . $med->getReadOnly() . "<br/>";
		echo "med: " . $med->getHostDrive() . "<br/>";
	} else {
		echo "null media <br/>";
	}
}

$websessionManager->logoff($virtualbox->handle);
?>
The output:
Dos3.3.img
===============
media attach cnt: IDE Controller
media attach port: 0
media attach device: 0
media attach type: HardDisk
med: {dfb1310a-5d30-443d-ad72-6e274f6848b4}.vmdk
med: VMDK
med: HardDisk
med: Normal
med: LockedWrite
med: /Volumes/Virtualization/VirtualBox/Machines/Windows XP/Snapshots/{dfb1310a-5d30-443d-ad72-6e274f6848b4}.vmdk
med: 2091712512
med: 4096
med:
med:
===============
media attach cnt: IDE Controller
media attach port: 0
media attach device: 1
media attach type: DVD
null media
===============
media attach cnt: IDE Controller
media attach port: 1
media attach device: 0
media attach type: DVD
med: VBoxGuestAdditions.iso
med: RAW
med: DVD
med: Writethrough
med: LockedRead
med: /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso
med: 33470464
med: 31
med:
med:
===============
media attach cnt: Floppy Controller
media attach port: 0
media attach device: 0
media attach type: Floppy
med: Dos3.3.img
med: RAW
med: Floppy
med: Writethrough
med: LockedRead
med: /Volumes/Virtualization/VM Install Images/Dos3.3.img
med: 1474560
med: 1
med:
med:

It seems that the Virtualbox sees that a mount was issued, as I can see it in the GUI drop down with a checkmark next to the name, but the machine xml file does not get updated nor does the VM realize that a floppy has been inserted. So what am I doing wrong?

thanks,
michael
Sm0k1n
Posts: 18
Joined: 31. Mar 2010, 12:37
Primary OS: openSUSE
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows,Linux
Contact:

Re: vboxwebsrv sdk and php bindings

Post by Sm0k1n »

I think your issue is that you are not saving the configuration. Put a $newMachine->saveSettings(); after you are done mounting, etc, etc. There are two other differences between your mounting solution and mine. I don't lockRead() the medium and I force the mount (the last boolean param of mountMedium())... so if saving doesn't work, try changing these.
VBox WMI - Web application for managing multiple VirtualBox servers (http://code.google.com/p/vbox-wmi/)
mathomp
Posts: 3
Joined: 8. Apr 2010, 17:08
Primary OS: Mac OS X Leopard
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows

Re: vboxwebsrv sdk and php bindings

Post by mathomp »

Thanks, I tried what you suggested but it still did not work but instead gave me a nice error to search on with the saveSettings() call. After searching, reading and re-reading the API Doc's, I finally got it to work! :-) I really need to read the Doc's more carefully...

Here is the solution:

Code: Select all

require_once('vboxServiceWrappers.php');

//Connect to webservice
$connection = new SoapClient("vboxwebService.wsdl", array('location' => "http://localhost:18083/", 'trace' => 1));

//Logon to webservice
$websessionManager = new IWebsessionManager($connection);

$virtualbox = $websessionManager->logon("null","null");

$newMachine = $virtualbox->findMachine("Windows XP");

// need to get a session object
$session1 = $websessionManager->getSessionObject($virtualbox->handle);

//need to get the uuid of the machine you wish to work on
$uuid = $newMachine->id;

// in my case I wish to add floppy media to a running vm so I open an existing session
$virtualbox->openExistingSession($session1, $uuid);

// because the machine is running I need to access the console, if the machine was off you dont need this? just use the machine ref from the session object?
$console1 = $session1->console;

//ok, now we need to get machine reference from the IConsole object that is from the ISession object from above
//so all changes to the vm are handled through the sessionMachine object
$sessionMachine = $console1->machine;

//mount medium
$sessionMachine->mountMedium("Floppy Controller", 0, 0, "ca7d3782-6c20-4106-a78d-d40b54a00355", true);
$fff = $sessionMachine->getMediumAttachment("Floppy Controller", 0, 0);
echo $fff->getMedium()->name . "<br/>";

// and finally save the settings
$sessionMachine->saveSettings();

//close the session
$session1->close();

// now lets see if it worked
$medias = $newMachine->getMediumAttachments();
foreach($medias as $ma) {
	echo "=============== <br/>";
	echo "media attach cnt: " . $ma->getController() . "<br/>";
	echo "media attach port: " . $ma->getPort() . "<br/>";
	echo "media attach device: " . $ma->getDevice() . "<br/>";
	echo "media attach type: " . $ma->getType() . "<br/>";
	
	$med = $ma->getMedium();
	if($med->handle != null) {
		echo "med: " . $med->name . "<br/>";
		echo "med: " . $med->getFormat() . "<br/>";
		echo "med: " . $med->getDeviceType() . "<br/>";
		echo "med: " . $med->getType() . "<br/>";
		echo "med: " . $med->getState() . "<br/>";
		echo "med: " . $med->getLocation() . "<br/>";
		echo "med: " . $med->getSize() . "<br/>";
		echo "med: " . $med->getLogicalSize() . "<br/>";
		echo "med: " . $med->getReadOnly() . "<br/>";
		echo "med: " . $med->getHostDrive() . "<br/>";
	} else {
		echo "null media <br/>";
	}
}

$websessionManager->logoff($virtualbox->handle);
thanks again for your help.

michael
Post Reply