qemu guest automation

前端 未结 8 785
生来不讨喜
生来不讨喜 2021-02-09 02:39

I\'ve not been able to find any documentation stating the existence of an API that can be used to automate things inside of a qemu guest.

For example, I would like to la

8条回答
  •  攒了一身酷
    2021-02-09 03:43

    PyQemu can theoretically do this. I've used it in the past, although it looks like a stale project now. It provides a python agent (the equivalent of VMWare guest tools) to run on the guest, communicating with the host via serial port. You can get proxies to python modules running in the context of the VM, and any communication with them is marshaled over the serial port. In the following example, AutoIt is being used to automate Notepad:

    machine = PyQemu.GetProxy("win2k")
    
    # Wrap the machine object in another proxy representing the 'os'
    # module running inside the VM.
    os = PyQemu.vm.Module(machine,"os")
    
    # NOTE: This is running on the VM!
    os.system("notepad")
    
    # Get an IDispatch object representing the autoit ActiveX control
    autoit = PyQemu.vm.Dispatch(machine,"AutoItX3.Control")
    
    # See if a window is active on the VM
    state = autoit.WinActive("Untitled -")
    

    Caveat: Due to using the serial port it is far from quick (regardless of serial speed settings), so perhaps best to transfer any bulk data by other means, e.g. Virtual FAT disk image.

提交回复
热议问题