#include "virsh-domain.h"
#include "xml.h"
#include "virtypedparam.h"
+#include "json.h"
/*
* "capabilities" command
static const vshCmdOptDef opts_qemu_monitor_command[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
{"hmp", VSH_OT_BOOL, 0, N_("command is in human monitor protocol")},
+ {"pretty", VSH_OT_BOOL, 0,
+ N_("pretty-print any qemu monitor protocol output")},
{"cmd", VSH_OT_ARGV, VSH_OFLAG_REQ, N_("command")},
{NULL, 0, 0, NULL}
};
const vshCmdOpt *opt = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
bool pad = false;
+ virJSONValuePtr pretty = NULL;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
}
monitor_cmd = virBufferContentAndReset(&buf);
- if (vshCommandOptBool(cmd, "hmp"))
+ if (vshCommandOptBool(cmd, "hmp")) {
+ if (vshCommandOptBool(cmd, "pretty")) {
+ vshError(ctl, _("--hmp and --pretty are not compatible"));
+ goto cleanup;
+ }
flags |= VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP;
+ }
if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0)
goto cleanup;
+ if (vshCommandOptBool(cmd, "pretty")) {
+ char *tmp;
+ pretty = virJSONValueFromString(result);
+ if (pretty && (tmp = virJSONValueToString(pretty, true))) {
+ VIR_FREE(result);
+ result = tmp;
+ } else {
+ vshResetLibvirtError();
+ }
+ }
vshPrint(ctl, "%s\n", result);
ret = true;
cleanup:
VIR_FREE(result);
VIR_FREE(monitor_cmd);
+ virJSONValueFree(pretty);
if (dom)
virDomainFree(dom);
issues with the guest ABI changing upon migration, and hotunplug
may not work.
-=item B<qemu-monitor-command> I<domain> [I<--hmp>] I<command>...
+=item B<qemu-monitor-command> I<domain> { [I<--hmp>] | [I<--pretty>] }
+I<command>...
Send an arbitrary monitor command I<command> to domain I<domain> through the
qemu monitor. The results of the command will be printed on stdout. If
I<--hmp> is passed, the command is considered to be a human monitor command
and libvirt will automatically convert it into QMP if needed. In that case
-the result will also be converted back from QMP. If more than one argument
-is provided for I<command>, they are concatenated with a space in between
-before passing the single command to the monitor.
+the result will also be converted back from QMP. If I<--pretty> is given,
+and the monitor uses QMP, then the output will be pretty-printed. If more
+than one argument is provided for I<command>, they are concatenated with a
+space in between before passing the single command to the monitor.
=back