[vbox-dev] How to discard VM state changes ?

Alex alex.lavoro.propio at gmail.com
Wed Aug 11 11:07:13 GMT 2010


I am trying to automate a VM remotely with JAX-WS API.

(1) Power up VM.
(2) Execute some jobs in VM, this changes the states of VM.
(3) Power down VM.
(4) Restore the VM state before (1).

I have an implementation which works, but I have to *manually* create
a snapshot before (1) and restore to this snapshot after (4). I want
to eliminiate the need of this manual step. Is it even possible ?

Here is my implementation (suppose a snapshot 'tmp' has already be
taken for 'machine'):

<code>
// websessionmgr is IWebsessionManager, vbox is IVirtualBox
ISession session = websessionmgr.getSessionObject(vbox);
// This also powers up the machine automaticallly.
IProgress prog = vbox.openRemoteSession(session, machine.getId(),
"headless", "");
prog.waitForCompletion(-1);

/** Execute some testing jobs in VM 'machine' here. For example,
installing some softwares but without uninstalling it since it's
usually difficult and we plan to restore the VM state. */

// Power it down and restore it to the snapshot 'tmp'.
session = websessionmgr.getSessionObject(vbox);
prog = session.getConsole().powerDown();
prog.waitForCompletion(-1);

vbox.openSession(session, machine.getId());
ISnapshot tmp_snapshot = machine.findSnapshot("tmp");
prog = session.getConsole().restoreSnapshot(tmp_snapshot);
prog.waitForCompletion(-1);
</code>

Alex Barna.




More information about the vbox-dev mailing list