virsh: Implement vshTable API to nwfilter-list and nwfilterbinding-list

Signed-off-by: Simon Kobyda <skobyda@redhat.com>
This commit is contained in:
Simon Kobyda 2018-09-21 16:17:15 +02:00 committed by Michal Privoznik
parent cf12efe088
commit c2b9cf6733

View File

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