virsh: Implement vshTable API to domiflist

Signed-off-by: Simon Kobyda <skobyda@redhat.com>
This commit is contained in:
Simon Kobyda 2018-09-21 16:17:20 +02:00 committed by Michal Privoznik
parent 075dd1185d
commit 063509a193

View File

@ -693,6 +693,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
int ninterfaces; int ninterfaces;
xmlNodePtr *interfaces = NULL; xmlNodePtr *interfaces = NULL;
size_t i; size_t i;
vshTablePtr table = NULL;
if (vshCommandOptBool(cmd, "inactive")) if (vshCommandOptBool(cmd, "inactive"))
flags |= VIR_DOMAIN_XML_INACTIVE; flags |= VIR_DOMAIN_XML_INACTIVE;
@ -704,16 +705,17 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
if (ninterfaces < 0) if (ninterfaces < 0)
goto cleanup; goto cleanup;
vshPrintExtra(ctl, "%-10s %-10s %-10s %-11s %s\n", _("Interface"), table = vshTableNew(_("Interface"), _("Type"),
_("Type"), _("Source"), _("Model"), _("MAC")); _("Source"), _("Model"), _("MAC"), NULL);
vshPrintExtra(ctl, "-------------------------------------------------------\n"); if (!table)
goto cleanup;
for (i = 0; i < ninterfaces; i++) { for (i = 0; i < ninterfaces; i++) {
char *type = NULL; VIR_AUTOFREE(char *) type = NULL;
char *source = NULL; VIR_AUTOFREE(char *) source = NULL;
char *target = NULL; VIR_AUTOFREE(char *) target = NULL;
char *model = NULL; VIR_AUTOFREE(char *) model = NULL;
char *mac = NULL; VIR_AUTOFREE(char *) mac = NULL;
ctxt->node = interfaces[i]; ctxt->node = interfaces[i];
type = virXPathString("string(./@type)", ctxt); type = virXPathString("string(./@type)", ctxt);
@ -728,23 +730,22 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
model = virXPathString("string(./model/@type)", ctxt); model = virXPathString("string(./model/@type)", ctxt);
mac = virXPathString("string(./mac/@address)", ctxt); mac = virXPathString("string(./mac/@address)", ctxt);
vshPrint(ctl, "%-10s %-10s %-10s %-11s %-10s\n", if (vshTableRowAppend(table,
target ? target : "-", target ? target : "-",
type, type,
source ? source : "-", source ? source : "-",
model ? model : "-", model ? model : "-",
mac ? mac : "-"); mac ? mac : "-",
NULL) < 0)
VIR_FREE(type); goto cleanup;
VIR_FREE(source);
VIR_FREE(target);
VIR_FREE(model);
VIR_FREE(mac);
} }
vshTablePrintToStdout(table, ctl);
ret = true; ret = true;
cleanup: cleanup:
vshTableFree(table);
VIR_FREE(interfaces); VIR_FREE(interfaces);
xmlFreeDoc(xmldoc); xmlFreeDoc(xmldoc);
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);