I'd like to create a small python script that will clone an existing virtual machine (on Windows). I can easily clone existing disk (or snapshot) to a new base image with the following code:
Code: Select all
from vboxapi import VirtualBoxManager
vbm = VirtualBoxManager(None, None)
from vboxapi.VirtualBox_constants import VirtualBoxReflectionInfo
vbc = VirtualBoxReflectionInfo()
clone_hd = vbm.vbox.createHardDisk('', r'm:\virtualbox\clon')
source_hd = vbm.vbox.machines[6].hardDiskAttachments[0].hardDisk
progress = source_hd.cloneTo(clone_hd, vbc.HardDiskVariant_Standard, None)
progress.waitForCompletion(-1)
However, I'd like to preserve the differencing images of the machine [6]. It looks like cloneTo function should be able to do it but I have not been successful in it. I tried the following code:
Code: Select all
from vboxapi import VirtualBoxManager
vbm = VirtualBoxManager(None, None)
from vboxapi.VirtualBox_constants import VirtualBoxReflectionInfo
vbc = VirtualBoxReflectionInfo()
clone_roothd = vbm.vbox.createHardDisk('', r'm:\virtualbox\root')
source_roothd = vbm.vbox.machines[6].hardDiskAttachments[0].hardDisk.parent
progress = source_roothd.cloneTo(clone_roothd, vbc.HardDiskVariant_Standard, None)
progress.waitForCompletion(-1)
clone_childhd = vbm.vbox.createHardDisk('', r'm:\virtualbox\child')
source_childhd = vbm.vbox.machines[6].hardDiskAttachments[0].hardDisk
progress = source_childhd.cloneTo(clone_childhd, vbc.HardDiskVariant_Diff, clone_roothd)
progress.waitForCompletion(-1)
Parent UUID of the hard disk child does not match UUID of its parent hard disk stored in the media registry
I set clone_roothd as the root for clone hard disk - UUID {...379} - but the {...880b} UUID is UUID of the source_roothd and not of the clone_roothd.
Is this a bug? Or do I do something wrong? Does exist an example of using cloneTo function somewhere? Thanks.