[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt-users] Qemu-guest agent



On 21.05.2015 12:33, Umer Khan wrote:
> Hi all,
> 
> I am new to libvirt, I am trying to execute some commands inside guest
> domains from my host machine using libvirt-Python API. So far I have been
> able to open up a stream but I am not sure how to send commands on the
> stream (through virDomainOpenConsole). After hours of searching through
> different forums I found out that there is a utlity called qemu-guest agent
> which can solve my problem. But I am not sure how to enable this agent on
> host and domain, and how this will be used to communicate to guest domains.
> Any help in this matter will be really appreciated.
> 
> Thanks
> 
> 
> 


http://wiki.libvirt.org/page/Qemu_guest_agent

After you've set up the guest agent (both in libvirt and in guest), you
can passtrhough an arbitrary guest agent commands too:

http://git.qemu.org/?p=qemu.git;a=blob;f=qga/qapi-schema.json;h=b446dc729dc18f1f290e414bc857144cadc9931c;hb=HEAD

Although I should warn you that qemu-ga does not allow arbitrary OS
command execution. To do that you'd need to use a console. I think virsh
is a good example on that:

http://libvirt.org/git/?p=libvirt.git;a=blob;f=tools/virsh-console.c;h=f0faf8cb39f5242e023f785a5d3d957659c3ca0c;hb=HEAD#l308

Long story short, you create a new stream @st by calling virStreamNew().
Then you open a console and connect the stream onto it:
virDomainOpenConsole(dom, dev_name, st, flags); then you register two
events into the event loop, one to watch if STDIN is readable (= has
some data to send = somebody typed something), the other to watch if
STDOUT is writable (it can be redirected to a file or whatever, which is
not necessarily always writable). The third event you register is to
handle the stream. This is the idea:

streamEvent() {
  if (stream_readable) {
    read data from stream into terminal buffer
    make STDOUT handler listen to writable event
  }
  if (stream_writable and stream buffer != empty) {
    send data to stream from stream buffer
  }
  if (terminal buffer == empty)
    make stream handler listen to readable event
}

stdin_event() {
  read data from STDIN into stream buffer
  make stream handler listen to readable | writable event
}

stdout_event() {
  write data from terminal buffer to STDOUT
  if (terminal buffer == empty)
    temporarily disable stdout handler
}

I hope this makes it something clearer.

Michal


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]