#22158 new defect
VirtualBox API exports Host-Only adapter without name
回報者: | ana06 | 負責人: | |
---|---|---|---|
元件: | network | 版本: | VirtualBox-7.0.20 |
關鍵字: | API, Host-Only, HostOnly, | 副本: | ana06 |
Guest type: | all | Host type: | Linux |
描述
When I export an appliance adding a VM with a Host-Only adapter manually (using the GUI), the exported appliance include a name for the HostOnlyInterface and I can import and run the VM correctly:
<HostOnlyInterface name="vboxnet0"/>
But if I use the VirtualBox API to export an appliance adding a VM with a Host-Only adapter, the name of the HostOnlyInterface is missing, causing a "Nonexistent host networking interface, name (VERR_INTERNAL_ERROR)":
<HostOnlyInterface/>
I would expect the VirtualBox API to either export the name of the Host-Only adapter by default or accept a name, for example as part of the extraConfigValues
of the IVirtualSystemDescription
: 'type=HostOnly;name=vboxnet0'
.
I am using the following Python code (using virtualbox-python which is a wrapper for VirtualBox's COM API, but the issue is not Python related) to export the VM:
vbox = virtualbox.VirtualBox() vm = vbox.find_machine(VM_NAME) appliance = vbox.create_appliance() sys_description = vm.export_to(appliance, "name") appliance.write("ovf-1.0", [], PATH)
This code is part of the following script open-sourced as part of the FLARE-VM project: https://github.com/mandiant/flare-vm/blob/main/virtualbox/vbox-export-snapshots.py
I have tested this code in Debian with VirtualBox 7.0.20 and different hosts (Windows 10 and Ubuntu). In addition to this bug report, I have opened the ''Export to OVA with Host-Only adapter with name'' topic in the VirtualBox forum looking for solutions or workarounds to this issue.
Please let me know if there is anything I can do to help fixing the issue.
更動歷史 (2)
comment:2 3 月 前 由 編輯
The crux of the issue appears to be how to leverage the VirtualBox API to configure a VM to use host-only networking. The virtualbox-python code at:
https://github.com/mandiant/flare-vm/blob/main/virtualbox/vbox-export-snapshots.py#L41
configures the VM's networking using:
41 def change_network_adapters(vm, max_adapters): 42 for i in range(max_adapters): 43 adapter = vm.get_network_adapter(i) 44 adapter.attachment_type = NetType.host_only 45 vm.save_settings()
What's missing is a call to INetworkAdapter::setHostOnlyInterface() to assign a name to the host-only network interface, for example using:
adapter.host_only_interface = 'vboxnet0'
before the call to vm.save_settings() on line 45 above. With this in place then exporting the VM will include this information and the issue you encountered won't be seen.
The VirtualBox GUI makes both calls which is why a VM created to use host-only networking has the correct settings applied. When using VBoxManage both options can be specified at once using the following invocation for example for NIC 1:
$ VBoxManage modifyvm hostonly --nic1=hostonly --host-only-adapter1=vboxnet0
The example in the VirtualBox User Guide:
https://www.alldomusa.eu.org/manual/ch06.html#network_hostonly
states:
"On the command line, use VBoxManage modifyvm vmname --nic<x> hostonly"
which does change the network interface but it really should include the '--host-only-adapterN' option on the command line as well to show that both options are required to fully configure a host-only network interface. I will get the documentation updated so that this is clearer.
I did some more testing. Exporting a VM setting the hostonly adapter (with either virtualbox API and VBoxManage CLI) fails when I have never used the hostonly adapter of the VM as exporting does not set the name. It does not appear possible to use the API/VBoxManage CLI and I still think this is a virtualbox bug. The following manual woraround works in my use case: Set the network to hostonly (save the settings) and then back to NAT (save setting again). This ensures the hostonly adapter name is set and then the exporting using the virtualbox API and VBoxManage CLI works.