Pedro Badrutt Pedro Badrutt - 23 days ago 7
Python Question

How can I export a VirtualBox machine to OVA appliance using Python?

I need to create (export) a virtual machine (VirtualBox) to a OVA appliance.

I tried to use the

IMachine.export_to()
method (pyvbox) like this:

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')


The above code doesn't do what I want: no ova/ovf is created.

I think the appliance object wasn't created. How can I check that? And fix it if it's wrong?

Answer

Solved

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')