So... the VirtualBox SDK allows you to control VirtualBox programmatically. In particular from a selection of languages using either XPCOM or SOAP. I've been working with Python using the XPCOM method, which looks a bit like this...
vbox = xpcom.components.classes["@virtualbox.org/VirtualBox;1"].createInstance()
session = xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
default_id = "00000000-0000-0000-0000-000000000000"
mach = vbox.createMachine("my_new_vm_name", "Ubuntu", None, default_id)
vbox.registerMachine(mach)
Looking good? Well almost. It's just a shame that there's no good examples around to show you how to do this. After some experimentation, Hobnob and I settled for looking up the values and then dropping them into the code I was trying to write:
AccessMode_ReadWrite = 2
hd = vbox.openHardDisk("/vm_disks/mydisk.vdi", AccessMode_ReadWrite, False, "", False, "")
ifaces = xpcom.components.interfaces
hd = vbox.openHardDisk("/vm_disks/mydisk.vdi", ifaces.AccessMode.ReadWrite, False, "", False, "")
Easy when you know how, huh :) So now I can remove these lines from my code:
AccessMode_ReadWrite = 2
HardDiskType_Immutable = 1
HardDiskVariant_Standard = 0
ifaces.AccessMode.ReadWrite
ifaces.HardDiskType.Immutable
ifaces.HardDiskVariant.Standard
No comments:
Post a Comment