[libvirt] [PATCH 08/13] virsh: Implement vshTable API to domblklist

Simon Kobyda skobyda at redhat.com
Tue Sep 18 14:21:32 UTC 2018


Signed-off-by: Simon Kobyda <skobyda at redhat.com>
---
 tools/virsh-domain-monitor.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 05db825716..b9b6739287 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -589,6 +589,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
     char *device = NULL;
     char *target = NULL;
     char *source = NULL;
+    vshTablePtr table = NULL;
 
     if (vshCommandOptBool(cmd, "inactive"))
         flags |= VIR_DOMAIN_XML_INACTIVE;
@@ -603,12 +604,12 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     if (details)
-        vshPrintExtra(ctl, "%-10s %-10s %-10s %s\n", _("Type"),
-                      _("Device"), _("Target"), _("Source"));
+        table = vshTableNew("Type", "Device", "Target", "Source", NULL);
     else
-        vshPrintExtra(ctl, "%-10s %s\n", _("Target"), _("Source"));
+        table = vshTableNew("Target", "Source", NULL);
 
-    vshPrintExtra(ctl, "------------------------------------------------\n");
+    if (!table)
+        goto cleanup;
 
     for (i = 0; i < ndisks; i++) {
         ctxt->node = disks[i];
@@ -633,10 +634,13 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
                                 "|./source/@name"
                                 "|./source/@volume)", ctxt);
         if (details) {
-            vshPrint(ctl, "%-10s %-10s %-10s %s\n", type, device,
-                     target, source ? source : "-");
+            if (vshTableRowAppend(table, type, device, target,
+                                  source ? source : "-", NULL) < 0)
+                goto cleanup;
         } else {
-            vshPrint(ctl, "%-10s %s\n", target, source ? source : "-");
+            if (vshTableRowAppend(table, target,
+                                  source ? source : "-", NULL) < 0)
+                goto cleanup;
         }
 
         VIR_FREE(source);
@@ -645,9 +649,12 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
         VIR_FREE(type);
     }
 
+    vshTablePrintToStdout(table, ctl);
+
     ret = true;
 
  cleanup:
+    vshTableFree(table);
     VIR_FREE(source);
     VIR_FREE(target);
     VIR_FREE(device);
-- 
2.17.1




More information about the libvir-list mailing list