Closed josepegerent closed 7 years ago
Thanks for this report! I will look into this later tonight.
Was the machine running or not running? Was the machine a part of a session (ie session.machine
) or was it directly from VirtualBox.find_machine()
? Are you building a machine configuration from scratch or is this virtual machine already configured via the GUI?
So I can reproduce this on Windows 10, Python 3.5.2. Definitely seems like a bug!
I'm really confused why virtualbox isn't converting the enum into an integer as it does for all other types.
Just to answer your question, I'm creating the machine, it is not running yet. I have the same code running on Linux, but now I need this to run on windows as well.
vbox = virtualbox.VirtualBox() vm_hd_name = "HD" vm_hd_path = os.getcwd() + '/' + vm_hd_name + ".vdi" #set a path for the VM's HD's vm = vbox.create_machine("", vm_name, [], "", "forceOverwrite=1") # Create the VM bus = virtualbox.library.StorageBus(2) # 2 is a enum type and refers to SATA vm.add_storage_controller("SATA", bus) vm.set_boot_order(4, virtualbox.library.DeviceType.network) network_adapter = vm.get_network_adapter(0) # 0 - first adapter network_adapter.adapter_type = virtualbox.library.NetworkAdapterType.i82540_em network_adapter.enabled = True network_adapter.attachment_type = virtualbox.library.NetworkAttachmentType.internal network_adapter.internal_network = "node" network_adapter.cable_connected = True network_adapter.promisc_mode_policy = virtualbox.library.NetworkAdapterPromiscModePolicy.allow_all vm.save_settings() # save VM files vbox.register_machine(vm) # register the VM at VirtualBox (import)
I'm glad to hear you found a solution! I appreciate your attention, when you have the fix ready just update the thread and I will update our API.
Thank you.
I'm glad you said that it works on Linux, this means that it's something going wrong in the win32com module.
Is there a workaround I can do to bypass this error?
I'm not aware of one, I haven't found anything that works yet.
It does seem similar to an issue encountered a few years ago: https://github.com/mjdorma/pyvbox/issues/8#issuecomment-35508079
If a workaround is found, a solution could be added to library_ext to extend the NetworkAdapter interface.
Oh, to clarify, similar (same) COM error, but different interface so different issue ;).
Aha! I'm actually kind of surprised that this wasn't noticed earlier. It seems like any attribute which doesn't have a setXYZ()
method doesn't get the Enum
converted to an integer type before being passed to the COM interface. I'll open up a PR on this soon!
I've merged the fix, there should be a new release hopefully by the end of today or tomorrow. :)
ENVIRONMENT
SUMMARY
I am trying to set the network adapter type to virtualbox.library.NetworkAdapterType.i82540_em but I'm getting some error.
STEPS TO REPRODUCE
network_adapter = vm.get_network_adapter(0) # 0 - first adapter network_adapter.adapter_type = virtualbox.library.NetworkAdapterType.i82540_em
EXPECTED RESULTS
I expect to set the network adapter type to virtualbox.library.NetworkAdapterType.i82540_em
ACTUAL RESULTS
network_adapter.adapter_type = virtualbox.library.NetworkAdapterType.i82540_em File "C:\Python27\lib\site-packages\virtualbox\library.py", line 22755, in adapter_type return self._set_attr("adapterType", value) File "C:\Python27\lib\site-packages\virtualbox\library_base.py", line 166, in _set_attr return setattr(self._i, name, value) File "C:\Python27\lib\site-packages\vboxapi__init__.py", line 193, in _CustomSetAttr return _g_dCOMForward['setattr'](self, ComifyName(sAttr), oValue) File "C:\Python27\lib\site-packages\win32com\client__init.py", line 474, in setattr__ self.oleobj.Invoke(*(args + (value,) + defArgs)) TypeError: Objects for SAFEARRAYS must be sequences (of sequences), or a buffer object. Win32 exception occurred releasing IUnknown at 0x005ea9c8 Win32 exception occurred releasing IUnknown at 0x0062eb28 Win32 exception occurred releasing IUnknown at 0x0062ec08