HowTo: Using Python XPCOM to modify machine configuration
Posted: 19. May 2011, 06:48
Applies to VirtualBox 4.0.8
I never found a complete example of this anywhere and the SDKRef loosely refers to this process without giving an example. Hopefully this makes life easier for others. This example illustrate how to change the memory of a system.
FYI... if you're going to use the above in production level code, be sure to place it the lock/unlock in a try finally block, otherwise bad things will occur if an error results in a failure to unlock, e.g.
This still leaves out a lot of error checking, so use this as a template and check with the SDKRef
I never found a complete example of this anywhere and the SDKRef loosely refers to this process without giving an example. Hopefully this makes life easier for others. This example illustrate how to change the memory of a system.
Code: Select all
>>> import vboxapi
>>> vbm = vboxapi.VirtualBoxManager(None, None)
>>> m = vbm.vbox.findMachine("example")
>>> session = vbm.mgr.getSessionObject(vbm.vbox)
>>> m.lockMachine(session, vbm.constants.LockType_Write)
>>> session.machine.memorySize = 1234
>>> session.machine.saveSettings()
>>> session.unlockMachine()Code: Select all
>>> try:
... m.lockMachine(session, vbm.constants.LockType_Write)
... session.machine.memorySize = 1234
... session.machine.saveSettings()
>>> finally:
... session.unlockMachine()