如何使用Python将VirtualBox机器导出到OVA设备?

2024-09-28 15:29:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要创建(导出)一个虚拟机(VirtualBox)到OVA/OVF设备。在

我尝试使用IMachine.export_to()方法(通过pyvbox包装器),如下所示:

import virtualbox
from virtualbox.library import ExportOptions


vbox = virtualbox.VirtualBox()
vm = vbox.find_machine(VM_NAME)

appliance = vbox.create_appliance()
p = appliance.write('ovf-2.0',
                    [ExportOptions.create_manifest],
                    '~/tmp/test5.ovf')
desc = slredmine.export_to(appliance, '~/tmp/test5.ovf')

上面的代码没有实现我想要的:没有创建ova/ovf。在

更新

指令顺序错误。请看我写在下面的答案。在


Tags: toimportcreateexporttmpvirtualboxvboxappliance
2条回答

根据pyvbox文档,它只能导出为OVF格式,但这并不重要,这取决于您想用它做什么。在

文件引用:

As with importing, first call IVirtualBox.create_appliance() to create an empty IAppliance object.

For each machine you would like to export, call IMachine.export_to() with the IAppliance object you just created. Each such call creates one instance of IVirtualSystemDescription inside the appliance.

If desired, call IVirtualSystemDescription.set_final_values() for each virtual system (machine) to override the suggestions made by the IMachine.export_to() routine.

Finally, call write() with a path specification to have the OVF file written.

如果你被卡住了,可以随意分享你的代码。在

已解决

import virtualbox
from virtualbox.library import ExportOptions

VM_NAME = 'foovmname'    

vbox = virtualbox.VirtualBox()
vm = vbox.find_machine(VM_NAME)

appliance = vbox.create_appliance()
desc = slredmine.export_to(appliance, VM_NAME)
p = appliance.write('ovf-2.0',
                    [ExportOptions.create_manifest],
                    '~/tmp/test5.ovf')

相关问题 更多 >