* [Qemu-devel] How to use monitor socket in python to connect VM?
@ 2017-09-04 6:17 Sam
2017-09-04 9:36 ` Daniel P. Berrange
0 siblings, 1 reply; 8+ messages in thread
From: Sam @ 2017-09-04 6:17 UTC (permalink / raw)
To: QEMU Developers
Hi all,
I'm using python socket to connect VM's monitor socket like this:
[root@yf-mos-test-net09 tests]# python
> Python 2.7.5 (default, Jun 24 2015, 00:41:19)
> [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from socket import *
> >>> sock = socket(AF_INET, SOCK_STREAM, 0)
> >>> sock.connect(('127.0.0.1', 55902))
> >>> sock.recv(1024)
> "QEMU 2.6.0 monitor - type 'help' for more information\r\n(qemu) "
> >>> sock.recv(1024)
> ^CTraceback (most recent call last):
> File "<stdin>", line 1, in <module>
> KeyboardInterrupt
> >>> sock.send('chardev-add
> socket,id=char-vhost_test_intf1,path=/usr/local/var/run/openvswitch/vhost_test_intf1,server=on')
> 106
> >>> sock.send('netdev_add
> vhost-user,id=vhost_test_intf1,chardev=char-vhost_test_intf1,vhostforce=on')
> 85
> >>> sock.send('device_add
> virtio-net-pci,netdev=vhost_test_intf1,mac=00:22:79:29:d2:6c,id=netdev-vhost_test_intf1')
> 98
> >>> sock.recv(1024)
> 'c\x1b[K\x1b[Dch\x1b[K\x1b[D\x1b[Dcha\x1b[K\x1b[D\x1b[D\x1b[Dchar\x1b[K\x1b[D\x1b[D\x1b[D\x1b[Dchard\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dcharde\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-a\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-ad\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> \x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> s\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> so\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> soc\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> sock\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> socke\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> socket\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> socket,\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> socket,i\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> socket,id\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D\x1b[Dchardev-add
> socket,id=\x1b[K\x1b[D\x1b[D\x1b[D\x1b[D'
> >>>
But as we see, there are problems:
1. commands like '>>> sock.send('chardev-add
socket,id=char-vhost_test_intf1,path=/usr/local/var/run/openvswitch/vhost_test_intf1,server=on')
106' does not work, this I'm very sure and I use some method to verify it.
2. commands like '>>> sock.recv(1024)' got a lot of unknown characters.
So is there some one who use python(or shell) to connect monitor socket of
VM? Could you please share the code or tell me the way to operate?
For example, should I send command with '(qemu) ' before my command? Should
I recv result by the end of '\r\n' or something?
Thank you~
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] How to use monitor socket in python to connect VM?
2017-09-04 6:17 [Qemu-devel] How to use monitor socket in python to connect VM? Sam
@ 2017-09-04 9:36 ` Daniel P. Berrange
2017-09-04 10:11 ` Sam
0 siblings, 1 reply; 8+ messages in thread
From: Daniel P. Berrange @ 2017-09-04 9:36 UTC (permalink / raw)
To: Sam; +Cc: QEMU Developers
On Mon, Sep 04, 2017 at 02:17:39PM +0800, Sam wrote:
> Hi all,
>
> I'm using python socket to connect VM's monitor socket like this:
>
> [root@yf-mos-test-net09 tests]# python
> > Python 2.7.5 (default, Jun 24 2015, 00:41:19)
> > [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> from socket import *
> > >>> sock = socket(AF_INET, SOCK_STREAM, 0)
> > >>> sock.connect(('127.0.0.1', 55902))
NB, running the QEMU monitor on an IP socket is not secure. There
is no authentication, and a monitor connection allows you do fully
exploit the user account QEMU is running under (because the user
can attach arbitrary files as virtual disks and thus access their
content). You always want to use a UNIX domain socket connection.
> > >>> sock.recv(1024)
> > "QEMU 2.6.0 monitor - type 'help' for more information\r\n(qemu) "
> > >>> sock.recv(1024)
[snip]
> But as we see, there are problems:
> 1. commands like '>>> sock.send('chardev-add
> socket,id=char-vhost_test_intf1,path=/usr/local/var/run/openvswitch/vhost_test_intf1,server=on')
> 106' does not work, this I'm very sure and I use some method to verify it.
> 2. commands like '>>> sock.recv(1024)' got a lot of unknown characters.
You're trying to interact with the *human* monitor here, so all the
garbage you see is the result of the readline library trying to
do interactive command processing for you.
To automate QEMU you should always use the QMP monitor. eg
$QEMU -qmp unix:/some/path/qemu.sock
>
> So is there some one who use python(or shell) to connect monitor socket of
> VM? Could you please share the code or tell me the way to operate?
You might want to look at scripts/qemu.py in the QEMU git tree. It is the
python code we use for communicating with QMP monitor in QEMU test suites.
You can probably use it as a starting point.
> For example, should I send command with '(qemu) ' before my command? Should
> I recv result by the end of '\r\n' or something?
No, you should use QMP and avoid this pain entirely :-)
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] How to use monitor socket in python to connect VM?
2017-09-04 9:36 ` Daniel P. Berrange
@ 2017-09-04 10:11 ` Sam
2017-09-04 10:16 ` Daniel P. Berrange
0 siblings, 1 reply; 8+ messages in thread
From: Sam @ 2017-09-04 10:11 UTC (permalink / raw)
To: Daniel P. Berrange; +Cc: QEMU Developers
Actually I use qga socket first(send json format command like {'execute':
'chardev-add', 'arguments': {'id': id, 'type': type}, 'params': params} by
qga socket, which is
/opt/cloud/workspace/servers/1925a92d-f003-4d77-871c-bce8f85229aa/qga.sock,
using the same script as first mail), but it response me "netdev_add is not
valid command"(it's reasonable, as guest OS could not operate 'netdev_add'
command), so I thought qga could not do this work, then I change to monitor.
After your explain, I still have few questions:
1. As in my thought, add net device is out of control of VM guest OS,
that's the reason why I got failed first time. But you said I could do this
work by QMP command, so your QMP command is different of my? And what this
command is?
2. The socket you refer above(like 'unix:/some/path/qemu.sock'), is it the
same socket of qga socket?
Thank you~
2017-09-04 17:36 GMT+08:00 Daniel P. Berrange <berrange@redhat.com>:
> On Mon, Sep 04, 2017 at 02:17:39PM +0800, Sam wrote:
> > Hi all,
> >
> > I'm using python socket to connect VM's monitor socket like this:
> >
> > [root@yf-mos-test-net09 tests]# python
> > > Python 2.7.5 (default, Jun 24 2015, 00:41:19)
> > > [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
> > > Type "help", "copyright", "credits" or "license" for more information.
> > > >>> from socket import *
> > > >>> sock = socket(AF_INET, SOCK_STREAM, 0)
> > > >>> sock.connect(('127.0.0.1', 55902))
>
> NB, running the QEMU monitor on an IP socket is not secure. There
> is no authentication, and a monitor connection allows you do fully
> exploit the user account QEMU is running under (because the user
> can attach arbitrary files as virtual disks and thus access their
> content). You always want to use a UNIX domain socket connection.
>
> > > >>> sock.recv(1024)
> > > "QEMU 2.6.0 monitor - type 'help' for more information\r\n(qemu) "
> > > >>> sock.recv(1024)
>
> [snip]
>
> > But as we see, there are problems:
> > 1. commands like '>>> sock.send('chardev-add
> > socket,id=char-vhost_test_intf1,path=/usr/local/var/run/
> openvswitch/vhost_test_intf1,server=on')
> > 106' does not work, this I'm very sure and I use some method to verify
> it.
> > 2. commands like '>>> sock.recv(1024)' got a lot of unknown characters.
>
> You're trying to interact with the *human* monitor here, so all the
> garbage you see is the result of the readline library trying to
> do interactive command processing for you.
>
> To automate QEMU you should always use the QMP monitor. eg
>
> $QEMU -qmp unix:/some/path/qemu.sock
>
> >
> > So is there some one who use python(or shell) to connect monitor socket
> of
> > VM? Could you please share the code or tell me the way to operate?
>
> You might want to look at scripts/qemu.py in the QEMU git tree. It is the
> python code we use for communicating with QMP monitor in QEMU test suites.
> You can probably use it as a starting point.
>
> > For example, should I send command with '(qemu) ' before my command?
> Should
> > I recv result by the end of '\r\n' or something?
>
> No, you should use QMP and avoid this pain entirely :-)
>
> Regards,
> Daniel
> --
> |: https://berrange.com -o- https://www.flickr.com/photos/
> dberrange :|
> |: https://libvirt.org -o-
> https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o- https://www.instagram.com/
> dberrange :|
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] How to use monitor socket in python to connect VM?
2017-09-04 10:11 ` Sam
@ 2017-09-04 10:16 ` Daniel P. Berrange
2017-09-04 12:31 ` Sam
0 siblings, 1 reply; 8+ messages in thread
From: Daniel P. Berrange @ 2017-09-04 10:16 UTC (permalink / raw)
To: Sam; +Cc: QEMU Developers
On Mon, Sep 04, 2017 at 06:11:44PM +0800, Sam wrote:
> Actually I use qga socket first(send json format command like {'execute':
> 'chardev-add', 'arguments': {'id': id, 'type': type}, 'params': params} by
> qga socket, which is
> /opt/cloud/workspace/servers/1925a92d-f003-4d77-871c-bce8f85229aa/qga.sock,
> using the same script as first mail), but it response me "netdev_add is not
> valid command"(it's reasonable, as guest OS could not operate 'netdev_add'
> command), so I thought qga could not do this work, then I change to monitor.
You're mixing up two different things. 'QGA' is the QEMU guest agent
which is a service than runs in the guest OS. 'QMP' is the QEMU monitor
socket which runs in the host OS. Both of these use the same JSON based
protocol, but take completely different commands.
You need to use 'QMP' for 'netdev_add', not 'QGA'.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] How to use monitor socket in python to connect VM?
2017-09-04 10:16 ` Daniel P. Berrange
@ 2017-09-04 12:31 ` Sam
2017-09-04 12:32 ` Sam
2017-09-04 12:59 ` Daniel P. Berrange
0 siblings, 2 replies; 8+ messages in thread
From: Sam @ 2017-09-04 12:31 UTC (permalink / raw)
To: Daniel P. Berrange; +Cc: QEMU Developers
Thank you, but I have to ask last question. My qemu is 2.6.0, and there is
no -qmp option :
[root@yf-mos-test-net09 ~]# ps aux | grep qemu
> root 5714 0.0 0.0 1669388 77736 ? Sl Sep01 0:09
> /usr/local/bin/qemu-system-x86_64_2.6.0 -enable-kvm -cpu
> qemu64,+vmx,+ssse3,+sse4.1,+sse4.2,+x2apic,+aes,+avx,+vme,+pat,+ss,+pclmulqdq,+xsave,level=13
> -machine pc,accel=kvm -chardev
> socket,id=hmqmondev,port=55919,host=127.0.0.1,nodelay,server,nowait -mon
> chardev=hmqmondev,id=hmqmon,mode=readline -rtc
> base=utc,clock=host,driftfix=none -usb -device usb-tablet -daemonize
> -nodefaults -nodefconfig -no-kvm-pit-reinjection -global
> kvm-pit.lost_tick_policy=discard -vga std -k en-us -smp 1 -name
> mvs5-huanghuai -m 1024 -boot order=cdn -vnc :19,password -drive
> file=/opt/cloud/workspace/disks/4a5148da-e34e-4c81-aada-12a247c0337e,if=none,id=drive_0,format=qcow2,cache=none,aio=native
> -device virtio-blk-pci,id=dev_drive_0,drive=drive_0,bus=pci.0,addr=0x5
> -drive
> file=/opt/cloud/workspace/disks/08eb3f72-07ba-44e9-8ee9-4ab662dbbd1f,if=none,id=drive_1,format=qcow2,cache=none,aio=native
> -device virtio-blk-pci,id=dev_drive_1,drive=drive_1,bus=pci.0,addr=0x6
> -device ide-cd,drive=ide0-cd0,bus=ide.1,unit=1 -drive
> id=ide0-cd0,media=cdrom,if=none -chardev
> socket,id=char-n-f879ac2f,path=/usr/local/var/run/openvswitch/n-f879ac2f,server
> -netdev type=vhost-user,id=n-f879ac2f,chardev=char-n-f879ac2f,vhostforce=on
> -device
> virtio-net-pci,netdev=n-f879ac2f,mac=00:22:f8:79:ac:2f,id=netdev-n-f879ac2f,addr=0xf
> -object
> memory-backend-file,id=mem,size=1024M,mem-path=/dev/hugepages,share=on
> -numa node,memdev=mem -mem-prealloc -pidfile
> /opt/cloud/workspace/servers/63ef2ec4-556f-47ea-93e0-23089bb59be5/pid
> -chardev
> socket,path=/opt/cloud/workspace/servers/63ef2ec4-556f-47ea-93e0-23089bb59be5/qga.sock,server,nowait,id=qga0
> -device virtio-serial -device
> virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 -incoming tcp:0:8081
After I use telnet like this `telnet localhost 55919`, then enter this cmd
line:
[root@yf-mos-test-net09 ~]# telnet localhost 55919
> Trying ::1...
> telnet: connect to address ::1: Connection refused
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> QEMU 2.6.0 monitor - type 'help' for more information
> (qemu) help
> help
> acl_add aclname match allow|deny [index] -- add a match rule to the access
> control list
> ...
> xp /fmt addr -- physical memory dump starting at 'addr'
> (qemu)
> (qemu)
(qemu) {"execute":"query-status"}
> {"execute":"query-status"}
> unknown command: '{"execute":"query-status"}'
And I send QMP json format command, it report error as above. So where is
the monitor socket? Why I got error while using QMP command?
2017-09-04 18:16 GMT+08:00 Daniel P. Berrange <berrange@redhat.com>:
> On Mon, Sep 04, 2017 at 06:11:44PM +0800, Sam wrote:
> > Actually I use qga socket first(send json format command like {'execute':
> > 'chardev-add', 'arguments': {'id': id, 'type': type}, 'params': params}
> by
> > qga socket, which is
> > /opt/cloud/workspace/servers/1925a92d-f003-4d77-871c-
> bce8f85229aa/qga.sock,
> > using the same script as first mail), but it response me "netdev_add is
> not
> > valid command"(it's reasonable, as guest OS could not operate
> 'netdev_add'
> > command), so I thought qga could not do this work, then I change to
> monitor.
>
> You're mixing up two different things. 'QGA' is the QEMU guest agent
> which is a service than runs in the guest OS. 'QMP' is the QEMU monitor
> socket which runs in the host OS. Both of these use the same JSON based
> protocol, but take completely different commands.
>
> You need to use 'QMP' for 'netdev_add', not 'QGA'.
>
> Regards,
> Daniel
> --
> |: https://berrange.com -o- https://www.flickr.com/photos/
> dberrange :|
> |: https://libvirt.org -o-
> https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o- https://www.instagram.com/
> dberrange :|
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] How to use monitor socket in python to connect VM?
2017-09-04 12:31 ` Sam
@ 2017-09-04 12:32 ` Sam
2017-09-04 13:00 ` Daniel P. Berrange
2017-09-04 12:59 ` Daniel P. Berrange
1 sibling, 1 reply; 8+ messages in thread
From: Sam @ 2017-09-04 12:32 UTC (permalink / raw)
To: Daniel P. Berrange; +Cc: QEMU Developers
There are two docs:
https://wiki.qemu.org/index.php/Documentation/QMP
https://en.wikibooks.org/wiki/QEMU/Monitor
I don't know which one is right...?
2017-09-04 20:31 GMT+08:00 Sam <batmanustc@gmail.com>:
> Thank you, but I have to ask last question. My qemu is 2.6.0, and there is
> no -qmp option :
>
> [root@yf-mos-test-net09 ~]# ps aux | grep qemu
>> root 5714 0.0 0.0 1669388 77736 ? Sl Sep01 0:09
>> /usr/local/bin/qemu-system-x86_64_2.6.0 -enable-kvm -cpu
>> qemu64,+vmx,+ssse3,+sse4.1,+sse4.2,+x2apic,+aes,+avx,+vme,
>> +pat,+ss,+pclmulqdq,+xsave,level=13 -machine pc,accel=kvm -chardev
>> socket,id=hmqmondev,port=55919,host=127.0.0.1,nodelay,server,nowait -mon
>> chardev=hmqmondev,id=hmqmon,mode=readline -rtc
>> base=utc,clock=host,driftfix=none -usb -device usb-tablet -daemonize
>> -nodefaults -nodefconfig -no-kvm-pit-reinjection -global
>> kvm-pit.lost_tick_policy=discard -vga std -k en-us -smp 1 -name
>> mvs5-huanghuai -m 1024 -boot order=cdn -vnc :19,password -drive
>> file=/opt/cloud/workspace/disks/4a5148da-e34e-4c81-aada-
>> 12a247c0337e,if=none,id=drive_0,format=qcow2,cache=none,aio=native
>> -device virtio-blk-pci,id=dev_drive_0,drive=drive_0,bus=pci.0,addr=0x5
>> -drive file=/opt/cloud/workspace/disks/08eb3f72-07ba-44e9-8ee9-
>> 4ab662dbbd1f,if=none,id=drive_1,format=qcow2,cache=none,aio=native
>> -device virtio-blk-pci,id=dev_drive_1,drive=drive_1,bus=pci.0,addr=0x6
>> -device ide-cd,drive=ide0-cd0,bus=ide.1,unit=1 -drive
>> id=ide0-cd0,media=cdrom,if=none -chardev socket,id=char-n-f879ac2f,
>> path=/usr/local/var/run/openvswitch/n-f879ac2f,server -netdev
>> type=vhost-user,id=n-f879ac2f,chardev=char-n-f879ac2f,vhostforce=on
>> -device virtio-net-pci,netdev=n-f879ac2f,mac=00:22:f8:79:ac:
>> 2f,id=netdev-n-f879ac2f,addr=0xf -object memory-backend-file,id=mem,
>> size=1024M,mem-path=/dev/hugepages,share=on -numa node,memdev=mem
>> -mem-prealloc -pidfile /opt/cloud/workspace/servers/
>> 63ef2ec4-556f-47ea-93e0-23089bb59be5/pid -chardev socket,path=/opt/cloud/
>> workspace/servers/63ef2ec4-556f-47ea-93e0-23089bb59be5/qga.sock,server,nowait,id=qga0
>> -device virtio-serial -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
>> -incoming tcp:0:8081
>
>
> After I use telnet like this `telnet localhost 55919`, then enter this
> cmd line:
>
> [root@yf-mos-test-net09 ~]# telnet localhost 55919
>> Trying ::1...
>> telnet: connect to address ::1: Connection refused
>> Trying 127.0.0.1...
>> Connected to localhost.
>> Escape character is '^]'.
>> QEMU 2.6.0 monitor - type 'help' for more information
>> (qemu) help
>> help
>> acl_add aclname match allow|deny [index] -- add a match rule to the
>> access control list
>> ...
>> xp /fmt addr -- physical memory dump starting at 'addr'
>> (qemu)
>> (qemu)
>
> (qemu) {"execute":"query-status"}
>> {"execute":"query-status"}
>> unknown command: '{"execute":"query-status"}'
>
>
>
> And I send QMP json format command, it report error as above. So where is
> the monitor socket? Why I got error while using QMP command?
>
>
> 2017-09-04 18:16 GMT+08:00 Daniel P. Berrange <berrange@redhat.com>:
>
>> On Mon, Sep 04, 2017 at 06:11:44PM +0800, Sam wrote:
>> > Actually I use qga socket first(send json format command like
>> {'execute':
>> > 'chardev-add', 'arguments': {'id': id, 'type': type}, 'params': params}
>> by
>> > qga socket, which is
>> > /opt/cloud/workspace/servers/1925a92d-f003-4d77-871c-bce8f85
>> 229aa/qga.sock,
>> > using the same script as first mail), but it response me "netdev_add is
>> not
>> > valid command"(it's reasonable, as guest OS could not operate
>> 'netdev_add'
>> > command), so I thought qga could not do this work, then I change to
>> monitor.
>>
>> You're mixing up two different things. 'QGA' is the QEMU guest agent
>> which is a service than runs in the guest OS. 'QMP' is the QEMU monitor
>> socket which runs in the host OS. Both of these use the same JSON based
>> protocol, but take completely different commands.
>>
>> You need to use 'QMP' for 'netdev_add', not 'QGA'.
>>
>> Regards,
>> Daniel
>> --
>> |: https://berrange.com -o- https://www.flickr.com/photos/
>> dberrange :|
>> |: https://libvirt.org -o-
>> https://fstop138.berrange.com :|
>> |: https://entangle-photo.org -o- https://www.instagram.com/dber
>> range :|
>>
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] How to use monitor socket in python to connect VM?
2017-09-04 12:31 ` Sam
2017-09-04 12:32 ` Sam
@ 2017-09-04 12:59 ` Daniel P. Berrange
1 sibling, 0 replies; 8+ messages in thread
From: Daniel P. Berrange @ 2017-09-04 12:59 UTC (permalink / raw)
To: Sam; +Cc: QEMU Developers
On Mon, Sep 04, 2017 at 08:31:29PM +0800, Sam wrote:
> Thank you, but I have to ask last question. My qemu is 2.6.0, and there is
> no -qmp option :
QEMU 2.6.0 supports it, but whatever person/application has run
the QEMU process shown here has not used the -qmp arg. You'll
need to get that changed somehow.
>
> [root@yf-mos-test-net09 ~]# ps aux | grep qemu
> > root 5714 0.0 0.0 1669388 77736 ? Sl Sep01 0:09
> > /usr/local/bin/qemu-system-x86_64_2.6.0 -enable-kvm -cpu
> > qemu64,+vmx,+ssse3,+sse4.1,+sse4.2,+x2apic,+aes,+avx,+vme,+pat,+ss,+pclmulqdq,+xsave,level=13
> > -machine pc,accel=kvm -chardev
> > socket,id=hmqmondev,port=55919,host=127.0.0.1,nodelay,server,nowait -mon
> > chardev=hmqmondev,id=hmqmon,mode=readline -rtc
> > base=utc,clock=host,driftfix=none -usb -device usb-tablet -daemonize
> > -nodefaults -nodefconfig -no-kvm-pit-reinjection -global
> > kvm-pit.lost_tick_policy=discard -vga std -k en-us -smp 1 -name
> > mvs5-huanghuai -m 1024 -boot order=cdn -vnc :19,password -drive
> > file=/opt/cloud/workspace/disks/4a5148da-e34e-4c81-aada-12a247c0337e,if=none,id=drive_0,format=qcow2,cache=none,aio=native
> > -device virtio-blk-pci,id=dev_drive_0,drive=drive_0,bus=pci.0,addr=0x5
> > -drive
> > file=/opt/cloud/workspace/disks/08eb3f72-07ba-44e9-8ee9-4ab662dbbd1f,if=none,id=drive_1,format=qcow2,cache=none,aio=native
> > -device virtio-blk-pci,id=dev_drive_1,drive=drive_1,bus=pci.0,addr=0x6
> > -device ide-cd,drive=ide0-cd0,bus=ide.1,unit=1 -drive
> > id=ide0-cd0,media=cdrom,if=none -chardev
> > socket,id=char-n-f879ac2f,path=/usr/local/var/run/openvswitch/n-f879ac2f,server
> > -netdev type=vhost-user,id=n-f879ac2f,chardev=char-n-f879ac2f,vhostforce=on
> > -device
> > virtio-net-pci,netdev=n-f879ac2f,mac=00:22:f8:79:ac:2f,id=netdev-n-f879ac2f,addr=0xf
> > -object
> > memory-backend-file,id=mem,size=1024M,mem-path=/dev/hugepages,share=on
> > -numa node,memdev=mem -mem-prealloc -pidfile
> > /opt/cloud/workspace/servers/63ef2ec4-556f-47ea-93e0-23089bb59be5/pid
> > -chardev
> > socket,path=/opt/cloud/workspace/servers/63ef2ec4-556f-47ea-93e0-23089bb59be5/qga.sock,server,nowait,id=qga0
> > -device virtio-serial -device
> > virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 -incoming tcp:0:8081
>
>
> After I use telnet like this `telnet localhost 55919`, then enter this cmd
> line:
>
> [root@yf-mos-test-net09 ~]# telnet localhost 55919
> > Trying ::1...
> > telnet: connect to address ::1: Connection refused
> > Trying 127.0.0.1...
> > Connected to localhost.
> > Escape character is '^]'.
> > QEMU 2.6.0 monitor - type 'help' for more information
> > (qemu) help
> > help
> > acl_add aclname match allow|deny [index] -- add a match rule to the access
> > control list
> > ...
> > xp /fmt addr -- physical memory dump starting at 'addr'
> > (qemu)
> > (qemu)
>
> (qemu) {"execute":"query-status"}
> > {"execute":"query-status"}
> > unknown command: '{"execute":"query-status"}'
This won't work - you're trying to send QMP commands to the HMP - they
speak completely different protocols.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] How to use monitor socket in python to connect VM?
2017-09-04 12:32 ` Sam
@ 2017-09-04 13:00 ` Daniel P. Berrange
0 siblings, 0 replies; 8+ messages in thread
From: Daniel P. Berrange @ 2017-09-04 13:00 UTC (permalink / raw)
To: Sam; +Cc: QEMU Developers
On Mon, Sep 04, 2017 at 08:32:38PM +0800, Sam wrote:
> There are two docs:
>
> https://wiki.qemu.org/index.php/Documentation/QMP
This one is right
> https://en.wikibooks.org/wiki/QEMU/Monitor
This refers to the older Human Monitor Protocol (HMP)
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-09-04 13:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-04 6:17 [Qemu-devel] How to use monitor socket in python to connect VM? Sam
2017-09-04 9:36 ` Daniel P. Berrange
2017-09-04 10:11 ` Sam
2017-09-04 10:16 ` Daniel P. Berrange
2017-09-04 12:31 ` Sam
2017-09-04 12:32 ` Sam
2017-09-04 13:00 ` Daniel P. Berrange
2017-09-04 12:59 ` Daniel P. Berrange
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).