提交 531c8581 编写于 作者: E Eric Blake

virsh: concatenate qemu-monitor-command arguments

Call me lazy, but:

virsh qemu-monitor-command dom --hmp info status

is nicer than:

virsh qemu-monitor-command dom --hmp 'info status'

* tools/virsh.c (cmdQemuMonitorCommand): Allow multiple arguments,
for convenience.
上级 2ce90ea2
...@@ -12476,8 +12476,8 @@ static const vshCmdInfo info_qemu_monitor_command[] = { ...@@ -12476,8 +12476,8 @@ static const vshCmdInfo info_qemu_monitor_command[] = {
static const vshCmdOptDef opts_qemu_monitor_command[] = { static const vshCmdOptDef opts_qemu_monitor_command[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
{"cmd", VSH_OT_DATA, VSH_OFLAG_REQ, N_("command")},
{"hmp", VSH_OT_BOOL, 0, N_("command is in human monitor protocol")}, {"hmp", VSH_OT_BOOL, 0, N_("command is in human monitor protocol")},
{"cmd", VSH_OT_ARGV, VSH_OFLAG_REQ, N_("command")},
{NULL, 0, 0, NULL} {NULL, 0, 0, NULL}
}; };
...@@ -12486,9 +12486,12 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) ...@@ -12486,9 +12486,12 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
bool ret = false; bool ret = false;
const char *monitor_cmd = NULL; char *monitor_cmd = NULL;
char *result = NULL; char *result = NULL;
unsigned int flags = 0; unsigned int flags = 0;
const vshCmdOpt *opt = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
bool pad = false;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup; goto cleanup;
...@@ -12497,10 +12500,17 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) ...@@ -12497,10 +12500,17 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
if (dom == NULL) if (dom == NULL)
goto cleanup; goto cleanup;
if (vshCommandOptString(cmd, "cmd", &monitor_cmd) <= 0) { while ((opt = vshCommandOptArgv(cmd, opt))) {
vshError(ctl, "%s", _("missing monitor command")); if (pad)
virBufferAddChar(&buf, ' ');
pad = true;
virBufferAdd(&buf, opt->data, -1);
}
if (virBufferError(&buf)) {
vshPrint(ctl, "%s", _("Failed to collect command"));
goto cleanup; goto cleanup;
} }
monitor_cmd = virBufferContentAndReset(&buf);
if (vshCommandOptBool(cmd, "hmp")) if (vshCommandOptBool(cmd, "hmp"))
flags |= VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP; flags |= VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP;
...@@ -12514,6 +12524,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) ...@@ -12514,6 +12524,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
VIR_FREE(result); VIR_FREE(result);
VIR_FREE(monitor_cmd);
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
......
...@@ -1689,13 +1689,15 @@ attaching to an externally launched QEMU process. There may be ...@@ -1689,13 +1689,15 @@ attaching to an externally launched QEMU process. There may be
issues with the guest ABI changing upon migration, and hotunplug issues with the guest ABI changing upon migration, and hotunplug
may not work. may not work.
=item B<qemu-monitor-command> I<domain> I<command> [I<--hmp>] =item B<qemu-monitor-command> I<domain> [I<--hmp>] I<command>...
Send an arbitrary monitor command I<command> to domain I<domain> through the 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 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 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 and libvirt will automatically convert it into QMP if needed. In that case
the result will also be converted back from QMP. 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.
=back =back
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册