-
-
Save mjdorma/9044686 to your computer and use it in GitHub Desktop.
"""pyvbox: How to copy a file from a VM. | |
""" | |
import os | |
import virtualbox | |
# Assume machine is already running. | |
vbox = virtualbox.VirtualBox() | |
machine = vbox.find_machine("win7") | |
session = machine.create_session() | |
# copy notepad.exe to ./notepad.exe | |
gs = session.console.guest.create_session("mick", "password") | |
gs.copy_from("C:\\Windows\\System32\\notepad.exe", "notepad.exe") | |
gs.close() |
Never mind, my bad: The error above occurs if the VM isn't running yet, so either starting the machine manually or programmatically by adding a line
progress = machine.launch_vm_process(session, 'gui', '')
fixes this.
However, no matter what file I try to copy, they all fail with e.g.
OSError: Failed to find /bin/nano on guest
although the file is clearly there.
There's been an API change in the underlying VirtualBox version; quote from the PDF that comes as part of the VirtualBox SDK, page 390:
Renamed IGuestSession::copyTo to IGuestSession::fileCopyToGuest.
Renamed IGuestSession::copyFrom to IGuestSession::fileCopyFromGuest.
Using copy_to
fails with
AttributeError: Failed to find attribute copyTo in <virtualbox.library_ext.guest_session.IGuestSession object at 0x107966050>
Patching the sources to call fileCopyToGuest
instead of copyTo
fixes this. However, the file still doesn't seem to get copied; no error message, but no file on the VM either.
copy_from
fails with the error message mentioned earlier, despite the fact that the underlying method being called isn't there anymore. Maybe there's a bug in the exception handling somewhere.
Patching the sources to call fileCopyFromGuest
instead of copyFrom
doesn't fix this.
This fails on my Mac OS X 10.10.5 / VirtualBox 5.0.8 r103449 / pyvbox 0.2.2 with
How can I fix this ? Or is there an alternate way to boot up a VM ?