[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 4/4] 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.
---

This helped me test the previous patch :)

 tools/virsh.c   |   19 +++++++++++++++----
 tools/virsh.pod |    6 ++++--
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index b053ed0..ffdb2de 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12381,8 +12381,8 @@ static const vshCmdInfo info_qemu_monitor_command[] = {

 static const vshCmdOptDef opts_qemu_monitor_command[] = {
     {"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")},
+    {"cmd", VSH_OT_ARGV, VSH_OFLAG_REQ, N_("command")},
     {NULL, 0, 0, NULL}
 };

@@ -12391,9 +12391,12 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom = NULL;
     bool ret = false;
-    const char *monitor_cmd = NULL;
+    char *monitor_cmd = NULL;
     char *result = NULL;
     unsigned int flags = 0;
+    const vshCmdOpt *opt = NULL;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    bool pad = false;

     if (!vshConnectionUsability(ctl, ctl->conn))
         goto cleanup;
@@ -12402,10 +12405,17 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
     if (dom == NULL)
         goto cleanup;

-    if (vshCommandOptString(cmd, "cmd", &monitor_cmd) <= 0) {
-        vshError(ctl, "%s", _("missing monitor command"));
+    while ((opt = vshCommandOptArgv(cmd, opt))) {
+        virBufferAdd(&buf, opt->data, -1);
+        if (pad)
+            virBufferAddChar(&buf, ' ');
+        pad = true;
+    }
+    if (virBufferError(&buf)) {
+        vshPrint(ctl, "%s", _("Failed to collect command"));
         goto cleanup;
     }
+    monitor_cmd = virBufferContentAndReset(&buf);

     if (vshCommandOptBool(cmd, "hmp"))
         flags |= VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP;
@@ -12419,6 +12429,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)

 cleanup:
     VIR_FREE(result);
+    VIR_FREE(monitor_cmd);
     if (dom)
         virDomainFree(dom);

diff --git a/tools/virsh.pod b/tools/virsh.pod
index 01b8fd6..ec778bf 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1683,13 +1683,15 @@ attaching to an externally launched QEMU process. There may be
 issues with the guest ABI changing upon migration, and hotunplug
 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
 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.
+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

-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]