From nobody Mon Feb 9 00:20:14 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 1537280551742247.30532942069703; Tue, 18 Sep 2018 07:22:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5DC65285B4; Tue, 18 Sep 2018 14:22:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E9DF3091376; Tue, 18 Sep 2018 14:22:29 +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 CC41A4A471; Tue, 18 Sep 2018 14:22:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8IEM8PM000422 for ; Tue, 18 Sep 2018 10:22:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 26FA07A413; Tue, 18 Sep 2018 14:22:08 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73F9C7A432; Tue, 18 Sep 2018 14:22:07 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 16:21:37 +0200 Message-Id: <20180918142137.16258-14-skobyda@redhat.com> In-Reply-To: <20180918142137.16258-1-skobyda@redhat.com> References: <20180918142137.16258-1-skobyda@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [PATCH 13/13] virt-admin: Implement vshTable API to server-list and client-list 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Sep 2018 14:22:30 +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/virt-admin.c | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 63822bc13e..ac4c72efec 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -40,6 +40,7 @@ #include "virgettext.h" #include "virtime.h" #include "virt-admin-completer.h" +#include "vsh-table.h" =20 /* Gnulib doesn't guarantee SA_SIGINFO support. */ #ifndef SA_SIGINFO @@ -382,6 +383,7 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE= _UNUSED) char *uri =3D NULL; virAdmServerPtr *srvs =3D NULL; vshAdmControlPtr priv =3D ctl->privData; + vshTablePtr table =3D NULL; =20 /* Obtain a list of available servers on the daemon */ if ((nsrvs =3D virAdmConnectListServers(priv->conn, &srvs, 0)) < 0) { @@ -391,13 +393,28 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBU= TE_UNUSED) goto cleanup; } =20 - vshPrintExtra(ctl, " %-5s %-15s\n", "Id", "Name"); - vshPrintExtra(ctl, "---------------\n"); - for (i =3D 0; i < nsrvs; i++) - vshPrint(ctl, " %-5zu %-15s\n", i, virAdmServerGetName(srvs[i])); + table =3D vshTableNew("Id", "Name", NULL); + if (!table) + goto cleanup; + + for (i =3D 0; i < nsrvs; i++) { + char *idStr; + if (virAsprintf(&idStr, "%lu", i) < 0) + goto cleanup; + + if (vshTableRowAppend(table, + idStr, + virAdmServerGetName(srvs[i]), + NULL) < 0) + goto cleanup; + VIR_FREE(idStr); + } + + vshTablePrintToStdout(table, ctl); =20 ret =3D true; cleanup: + vshTableFree(table); if (srvs) { for (i =3D 0; i < nsrvs; i++) virAdmServerFree(srvs[i]); @@ -617,6 +634,7 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) virAdmServerPtr srv =3D NULL; virAdmClientPtr *clts =3D NULL; vshAdmControlPtr priv =3D ctl->privData; + vshTablePtr table =3D NULL; =20 if (vshCommandOptStringReq(ctl, cmd, "server", &srvname) < 0) return false; @@ -631,12 +649,12 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - vshPrintExtra(ctl, " %-5s %-15s %-15s\n%s\n", _("Id"), _("Transport"), - _("Connected since"), - "-------------------------" - "-------------------------"); + table =3D vshTableNew("Id", "Transport", "Connected sice", NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < nclts; i++) { + char *idStr; virAdmClientPtr client =3D clts[i]; id =3D virAdmClientGetID(client); transport =3D virAdmClientGetTransport(client); @@ -644,14 +662,22 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) ×tr) < 0) goto cleanup; =20 - vshPrint(ctl, " %-5llu %-15s %-15s\n", - id, vshAdmClientTransportToString(transport), timestr); + if (virAsprintf(&idStr, "%llu", id) < 0) + goto cleanup; + if (vshTableRowAppend(table, idStr, + vshAdmClientTransportToString(transport), + timestr, NULL) < 0) + goto cleanup; VIR_FREE(timestr); + VIR_FREE(idStr); } =20 + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: + vshTableFree(table); if (clts) { for (i =3D 0; i < nclts; i++) virAdmClientFree(clts[i]); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list