I have a scenario in which I'm supplied with three VDI files: "ubunutubase", "extrafiles1" and "extrafiles2" - extrafiles1 is a differencing disk based on ubunutubase and extrafiles2 is a differencing disk based on extrafiles1. These files have been generated by another user (potentially on another compatible machine) and I'd like to import the hierarchy into my VirtualBox instance programmatically.
Experimenting with IVirtualBox.openHardDisk() I can pass it a parent UUID but it attempts to create a new drive with that UUID which is not the behavior I want in this case - the drive already exists.
Code: Select all
>>> vbox = xpcom.components.classes["@virtualbox.org/VirtualBox;1"].createInstance()
>>> session = xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
>>> ifaces = xpcom.components.interfaces
>>> local_path = '/vm_images/.VirtualBox/HardDisks/{4edbe526-6d78-4ce9-885b-63dcce74de5c}.vdi'
>>> hd = vbox.openHardDisk(local_path, ifaces.AccessMode.ReadWrite, False, "", False, "")
>>> local_path = '/vm_images/.VirtualBox/HardDisks/{3e0569c2-d4fa-4a40-a7c9-f5fb148796c4}.vdi'
>>> hd = vbox.openHardDisk(local_path, ifaces.AccessMode.ReadWrite, False, "", True, "4edbe526-6d78-4ce9-885b-63dcce74de5c")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<XPCOMObject method 'openHardDisk'>", line 7, in openHardDisk
xpcom.Exception: 0x80070057 (Cannot register the hard disk '/vm_images/.VirtualBox/HardDisks/{3e0569c2-d4fa-4a40-a7c9-f5fb148796c4}.vdi' with UUID {4edbe526-6d78-4ce9-885b-63dcce74de5c} because a hard disk '/vm_images/.VirtualBox/HardDisks/{4edbe526-6d78-4ce9-885b-63dcce74de5c}.vdi' with UUID {4edbe526-6d78-4ce9-885b-63dcce74de5c} already exists in the media registry ('/home/sarah/.VirtualBox/VirtualBox.xml'))
Code: Select all
>>> hd = vbox.openHardDisk(local_path, ifaces.AccessMode.ReadWrite, False, "", False, "")Thanks,
-- Saff
(Using Python 2.6 and XPCOM, VirtualBox and SDK Version 3.0.0)