1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

virsh: Implement vsh-table to iface-list

Signed-off-by: Simon Kobyda <skobyda@redhat.com>
This commit is contained in:
Simon Kobyda 2018-09-21 16:17:12 +02:00 committed by Michal Privoznik
parent 2f754b26cb
commit 0396cf5336

View File

@ -48,6 +48,7 @@
#include "virutil.h" #include "virutil.h"
#include "virxml.h" #include "virxml.h"
#include "virstring.h" #include "virstring.h"
#include "vsh-table.h"
virInterfacePtr virInterfacePtr
virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
@ -356,6 +357,8 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
unsigned int flags = VIR_CONNECT_LIST_INTERFACES_ACTIVE; unsigned int flags = VIR_CONNECT_LIST_INTERFACES_ACTIVE;
virshInterfaceListPtr list = NULL; virshInterfaceListPtr list = NULL;
size_t i; size_t i;
bool ret = false;
vshTablePtr table = NULL;
if (inactive) if (inactive)
flags = VIR_CONNECT_LIST_INTERFACES_INACTIVE; flags = VIR_CONNECT_LIST_INTERFACES_INACTIVE;
@ -366,21 +369,29 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (!(list = virshInterfaceListCollect(ctl, flags))) if (!(list = virshInterfaceListCollect(ctl, flags)))
return false; return false;
vshPrintExtra(ctl, " %-20s %-10s %s\n", _("Name"), _("State"), table = vshTableNew(_("Name"), _("State"), _("MAC Address"), NULL);
_("MAC Address")); if (!table)
vshPrintExtra(ctl, "---------------------------------------------------\n"); goto cleanup;
for (i = 0; i < list->nifaces; i++) { for (i = 0; i < list->nifaces; i++) {
virInterfacePtr iface = list->ifaces[i]; virInterfacePtr iface = list->ifaces[i];
vshPrint(ctl, " %-20s %-10s %s\n", if (vshTableRowAppend(table,
virInterfaceGetName(iface), virInterfaceGetName(iface),
virInterfaceIsActive(iface) ? _("active") : _("inactive"), virInterfaceIsActive(iface) ? _("active")
virInterfaceGetMACString(iface)); : _("inactive"),
virInterfaceGetMACString(iface),
NULL) < 0)
goto cleanup;
} }
vshTablePrintToStdout(table, ctl);
ret = true;
cleanup:
vshTableFree(table);
virshInterfaceListFree(list); virshInterfaceListFree(list);
return true; return ret;
} }
/* /*