]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Implement vshTable API to nwfilter-list and nwfilterbinding-list
authorSimon Kobyda <skobyda@redhat.com>
Fri, 21 Sep 2018 14:17:15 +0000 (16:17 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 24 Sep 2018 07:09:14 +0000 (09:09 +0200)
Signed-off-by: Simon Kobyda <skobyda@redhat.com>
tools/virsh-nwfilter.c

index 1cdbe5053a3f596ef58c627af3a4762c4d3bb4d2..b680ea082c6299c86329ebfd25672ab462c52344 100644 (file)
@@ -31,6 +31,7 @@
 #include "viralloc.h"
 #include "virfile.h"
 #include "virutil.h"
+#include "vsh-table.h"
 
 virNWFilterPtr
 virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
@@ -359,26 +360,35 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     size_t i;
     char uuid[VIR_UUID_STRING_BUFLEN];
+    bool ret = false;
     virshNWFilterListPtr list = NULL;
+    vshTablePtr table = NULL;
 
     if (!(list = virshNWFilterListCollect(ctl, 0)))
         return false;
 
-    vshPrintExtra(ctl, " %-36s  %-20s \n", _("UUID"), _("Name"));
-    vshPrintExtra(ctl, "---------------------------------"
-                       "---------------------------------\n");
+    table = vshTableNew(_("UUID"), _("Name"), NULL);
+    if (!table)
+        goto cleanup;
 
     for (i = 0; i < list->nfilters; i++) {
         virNWFilterPtr nwfilter = list->filters[i];
 
         virNWFilterGetUUIDString(nwfilter, uuid);
-        vshPrint(ctl, " %-36s  %-20s\n",
-                 uuid,
-                 virNWFilterGetName(nwfilter));
+        if (vshTableRowAppend(table,
+                              uuid,
+                              virNWFilterGetName(nwfilter),
+                              NULL) < 0)
+            goto cleanup;
     }
 
+    vshTablePrintToStdout(table, ctl);
+
+    ret = true;
+ cleanup:
+    vshTableFree(table);
     virshNWFilterListFree(list);
-    return true;
+    return ret;
 }
 
 /*
@@ -714,25 +724,34 @@ static bool
 cmdNWFilterBindingList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     size_t i;
+    bool ret = false;
     virshNWFilterBindingListPtr list = NULL;
+    vshTablePtr table = NULL;
 
     if (!(list = virshNWFilterBindingListCollect(ctl, 0)))
         return false;
 
-    vshPrintExtra(ctl, " %-20s  %-20s \n", _("Port Dev"), _("Filter"));
-    vshPrintExtra(ctl, "---------------------------------"
-                       "---------------------------------\n");
+    table = vshTableNew(_("Port Dev"), _("Filter"), NULL);
+    if (!table)
+        goto cleanup;
 
     for (i = 0; i < list->nbindings; i++) {
         virNWFilterBindingPtr binding = list->bindings[i];
 
-        vshPrint(ctl, " %-20s  %-20s\n",
-                 virNWFilterBindingGetPortDev(binding),
-                 virNWFilterBindingGetFilterName(binding));
+        if (vshTableRowAppend(table,
+                              virNWFilterBindingGetPortDev(binding),
+                              virNWFilterBindingGetFilterName(binding),
+                              NULL) < 0)
+            goto cleanup;
     }
 
+    vshTablePrintToStdout(table, ctl);
+
+    ret = true;
+ cleanup:
+    vshTableFree(table);
     virshNWFilterBindingListFree(list);
-    return true;
+    return ret;
 }