From nobody Mon Feb 9 12:24:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537539459019973.5372247599887; Fri, 21 Sep 2018 07:17:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E86BE308A967; Fri, 21 Sep 2018 14:17:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4C9C171C4; Fri, 21 Sep 2018 14:17:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 65DA0181A13A; Fri, 21 Sep 2018 14:17:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LEHU6s028237 for ; Fri, 21 Sep 2018 10:17:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 075F053C21; Fri, 21 Sep 2018 14:17:30 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55B1517964; Fri, 21 Sep 2018 14:17:29 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:13 +0200 Message-Id: <20180921141724.18879-3-skobyda@redhat.com> In-Reply-To: <20180921141724.18879-1-skobyda@redhat.com> References: <20180921141724.18879-1-skobyda@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [PATCH v2 02/13] virsh: Implement vshTable API to net-list and net-dhcp-leases X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 21 Sep 2018 14:17:37 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Simon Kobyda --- tools/virsh-network.c | 59 ++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index ca07fb568f..440b23d8a8 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -33,6 +33,7 @@ #include "virstring.h" #include "virtime.h" #include "conf/network_conf.h" +#include "vsh-table.h" =20 #define VIRSH_COMMON_OPT_NETWORK(_helpstr, cflags) \ {.name =3D "network", \ @@ -677,6 +678,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) bool optUUID =3D vshCommandOptBool(cmd, "uuid"); char uuid[VIR_UUID_STRING_BUFLEN]; unsigned int flags =3D VIR_CONNECT_LIST_NETWORKS_ACTIVE; + vshTablePtr table =3D NULL; =20 if (vshCommandOptBool(cmd, "inactive")) flags =3D VIR_CONNECT_LIST_NETWORKS_INACTIVE; @@ -705,10 +707,10 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATT= RIBUTE_UNUSED) return false; =20 if (optTable) { - vshPrintExtra(ctl, " %-20s %-10s %-13s %s\n", _("Name"), _("State"= ), - _("Autostart"), _("Persistent")); - vshPrintExtra(ctl, - "---------------------------------------------------= -------\n"); + table =3D vshTableNew(_("Name"), _("State"), _("Autostart"), + _("Persistent"), NULL); + if (!table) + goto cleanup; } =20 for (i =3D 0; i < list->nnets; i++) { @@ -722,11 +724,15 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATT= RIBUTE_UNUSED) else autostartStr =3D is_autostart ? _("yes") : _("no"); =20 - vshPrint(ctl, " %-20s %-10s %-13s %s\n", - virNetworkGetName(network), - virNetworkIsActive(network) ? _("active") : _("inacti= ve"), - autostartStr, - virNetworkIsPersistent(network) ? _("yes") : _("no")); + if (vshTableRowAppend(table, + virNetworkGetName(network), + virNetworkIsActive(network) ? + _("active") : _("inactive"), + autostartStr, + virNetworkIsPersistent(network) ? + _("yes") : _("no"), + NULL) < 0) + goto cleanup; } else if (optUUID) { if (virNetworkGetUUIDString(network, uuid) < 0) { vshError(ctl, "%s", _("Failed to get network's UUID")); @@ -738,8 +744,12 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTR= IBUTE_UNUSED) } } =20 + if (optTable) + vshTablePrintToStdout(table, ctl); + ret =3D true; cleanup: + vshTableFree(table); virshNetworkListFree(list); return ret; } @@ -1351,6 +1361,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *c= md) size_t i; unsigned int flags =3D 0; virNetworkPtr network =3D NULL; + vshTablePtr table =3D NULL; =20 if (vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0) return false; @@ -1366,15 +1377,15 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd = *cmd) /* Sort the list according to MAC Address/IAID */ qsort(leases, nleases, sizeof(*leases), virshNetworkDHCPLeaseSorter); =20 - vshPrintExtra(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n%s%s\n", - _("Expiry Time"), _("MAC address"), _("Protocol"), - _("IP address"), _("Hostname"), _("Client ID or DUID"), - "-------------------------------------------------------= ---", - "-------------------------------------------------------= --"); + table =3D vshTableNew(_("Expiry Time"), _("MAC address"), _("Protocol"= ), + _("IP address"), _("Hostname"), _("Client ID or DU= ID"), + NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < nleases; i++) { const char *typestr =3D NULL; - char *cidr_format =3D NULL; + VIR_AUTOFREE(char *) cidr_format =3D NULL; virNetworkDHCPLeasePtr lease =3D leases[i]; time_t expirytime_tmp =3D lease->expirytime; struct tm ts; @@ -1390,17 +1401,23 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd = *cmd) ignore_value(virAsprintf(&cidr_format, "%s/%d", lease->ipaddr, lease->prefix)); =20 - vshPrint(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n", - expirytime, EMPTYSTR(lease->mac), - EMPTYSTR(typestr), cidr_format, - EMPTYSTR(lease->hostname), EMPTYSTR(lease->clientid)); - - VIR_FREE(cidr_format); + if (vshTableRowAppend(table, + expirytime, + EMPTYSTR(lease->mac), + EMPTYSTR(typestr), + EMPTYSTR(cidr_format), + EMPTYSTR(lease->hostname), + EMPTYSTR(lease->clientid), + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: + vshTableFree(table); if (leases) { for (i =3D 0; i < nleases; i++) virNetworkDHCPLeaseFree(leases[i]); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list