Pedro Badrutt
Pedro Badrutt

Reputation: 11

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

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

I tried to use the IMachine.export_to() method (through pyvbox wrapper) 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.

UPDATE

The instructions order was wrong. See my answer written below.

Upvotes: 0

Views: 973

Answers (2)

Pedro Badrutt
Pedro Badrutt

Reputation: 11

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

Upvotes: 1

Marius
Marius

Reputation: 196

According to the pyvbox documentation, it can only export to OVF format, but that should not really matter, depending on what you want to do with it.

Documentation quote:

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.

Feel free to share your code if you are stuck.

Upvotes: 0

Related Questions