
On 12/12/19 11:18 AM, 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.
I'd give an example of the new syntax in the commit message: virsh qemu-monitor-command domain --qmp COMMAND '{ARGUMENTS...}' as shorthand for virsh qemu-monitor-command domain '"execute":"COMMAND", "arguments":{ARGUMENTS...}}' But the sugar is indeed nice (one less layer of {} JSON).
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/manpages/virsh.rst | 24 +++++++++++++++++------- tools/virsh-domain.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 10 deletions(-)
- virBufferTrim(&buf, " ", -1); + if ((opt = vshCommandOptArgv(ctl, cmd, opt))) + command = opt->data; + if ((opt = vshCommandOptArgv(ctl, cmd, opt))) + arguments = opt->data; + + if (!command || (arguments && vshCommandOptArgv(ctl, cmd, opt))) { + vshError(ctl, "%s", _("-qmp option requires 1 or 2 arguments")); + return false;
Should we allow concatenation and/or magic behavior based on whether the second argument starts with '{'? For example, virsh qemu-monitor-command --qmp COMMAND key1=1 'key2="str"' could be shorthand for virsh qemu-monitor-command '{"execute":"COMMAND", "arguments":{"key1":1, "key2":"str"}}' But further sugar can be a separate patch, so this one works as-is: Reviewed-by: Eric Blake <eblake@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org