[PATCH] virsh: Add QMP command wrapping for 'qemu-monitor-command'

Daniel P. Berrangé berrange at redhat.com
Wed Sep 15 14:50:14 UTC 2021


On Tue, Sep 14, 2021 at 05:16:11PM +0200, Peter Krempa wrote:
> Issuing simple QMP commands is pain as they need to be wrapped by the
> JSON wrapper:
> 
>  { "execute": "COMMAND" }
> 
> and optionally also:
> 
>  { "execute": "COMMAND", "arguments":...}
> 
> For simple commands without arguments we can add syntax sugar to virsh
> which allows simple usage of QMP and additionally prepares also for
> passing through of the 'arguments' section:
> 
>  virsh qemu-monitor-command --qmpwrap $VM query-status
> 
> is equivalent to
> 
>  virsh qemu-monitor-command $VM '{"execute":"query-status"}'
> 
> and
> 
>  virsh qemu-monitor-command --qmpwrap $VM query-named-block-nodes '{"flat":true}'
> 
> is equivalent to
> 
>  virsh qemu-monitor-command $VM '{"execute":"query-named-block-nodes", "arguments":{"flat":true}}'
> 
> Signed-off-by: Peter Krempa <pkrempa at redhat.com>
> ---
> 
> I originally called the flag '--qmp' but that could be confusing given
> that we have '--hmp'. On the other hand it's shorter so I wouldn't mind
> turning it back to '--qmp'.

How about just following a DWIM approach and not adding any flag

These two cases are trivially distinguished:

  virsh qemu-monitor-command $VM '{"execute":"query-named-block-nodes", "arguments":{"flat":true}}'

  virsh qemu-monitor-command $VM query-named-block-nodes '{"flat":true}'

because the second doesn't start with a '{'

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 :|




More information about the libvir-list mailing list