From nobody Tue May 7 18:09:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603189663; cv=none; d=zohomail.com; s=zohoarc; b=XgXX4GnM2L0bZoFCNYLl7Mz/rbGyPTZEEk7a7cTkUuYu88DNgkL97jcsz5FDNwTNt0Wa8Opd4SJv+Rtmw3V5nzGu8C9SIDtkbCGNgvuFnvO3wvv/gRbU3pTwOxmowaU7hmLsWNc9Z34cSPfQU63uy5QHMSAfbfAb3biwRL5CcBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603189663; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=oO4zkCakxoDRh40sPuKysBuho/yz21UZB4adU80chH0=; b=DepwzKDEvBy4QhWgI67Ifksoul+joQrjkq6Ey5gPtJ9YfO0mp+4fyts+Y9KXfjMTZnNSHR5H8v0wUQ3jeKwp60s6c5nSwh2vBdTh7VabylmgR7SXClhGseyc3VP/6Bi/WSfXUjjFhibKaq149kBmzxNtrMO5to1j3SAhy2qdDUY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603189663863175.80212705277074; Tue, 20 Oct 2020 03:27:43 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-Sr_4I8XROiizXsvS1vxPPQ-1; Tue, 20 Oct 2020 06:27:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 86BDB8049D7; Tue, 20 Oct 2020 10:27:35 +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 597146EF40; Tue, 20 Oct 2020 10:27:35 +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 DCF21180B657; Tue, 20 Oct 2020 10:27:34 +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 09KARXBU031160 for ; Tue, 20 Oct 2020 06:27:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8CF155760; Tue, 20 Oct 2020 10:27:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 390A02C31E for ; Tue, 20 Oct 2020 10:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603189662; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=oO4zkCakxoDRh40sPuKysBuho/yz21UZB4adU80chH0=; b=PkhxubDQy0BvZfQVvEK6LwDzCVdEjOV4KPV9Q9Glbf8i/xPIRLgvI+LA9inJNvJCLuUxzy +yqXY6cNdqaLYCachSZOMFeiDxxn/i7eMVaM41Ddr7IuTCxq8Re7K7EPBo4LtNQFXPX9xc sfQrSk+bLTIFBX0OUDWU1tLlaYJvrH4= X-MC-Unique: Sr_4I8XROiizXsvS1vxPPQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virsh: Allow listing just domain IDs Date: Tue, 20 Oct 2020 12:27:27 +0200 Message-Id: <3320f1978964fb6e02b48095cb5812a3bf3cbfd4.1603189445.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Some completers for libvirt related tools might want to list domain IDs only. Just like the one I've implemented for virt-viewer [1]. I've worked around it using some awk magic, but if it was possible to just 'virsh list --id' then I could drop awk. 1: https://www.redhat.com/archives/virt-tools-list/2019-May/msg00014.html Signed-off-by: Michal Privoznik --- I just realized that I've never sent this and it was sitting in a branch for 1.5 years. tools/virsh-domain-monitor.c | 41 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index e0491d48ac..9e66d573e6 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1919,6 +1919,10 @@ static const vshCmdOptDef opts_list[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("list domain names only") }, + {.name =3D "id", + .type =3D VSH_OT_BOOL, + .help =3D N_("list domain IDs only") + }, {.name =3D "table", .type =3D VSH_OT_BOOL, .help =3D N_("list table (default)") @@ -1945,6 +1949,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) bool optTable =3D vshCommandOptBool(cmd, "table"); bool optUUID =3D vshCommandOptBool(cmd, "uuid"); bool optName =3D vshCommandOptBool(cmd, "name"); + bool optID =3D vshCommandOptBool(cmd, "id"); size_t i; char *title; char uuid[VIR_UUID_STRING_BUFLEN]; @@ -1988,8 +1993,12 @@ cmdList(vshControl *ctl, const vshCmd *cmd) =20 VSH_EXCLUSIVE_OPTIONS("table", "name"); VSH_EXCLUSIVE_OPTIONS("table", "uuid"); + VSH_EXCLUSIVE_OPTIONS("table", "id"); + VSH_EXCLUSIVE_OPTIONS("all", "id"); + VSH_EXCLUSIVE_OPTIONS("inactive", "id"); + VSH_EXCLUSIVE_OPTIONS("state-shutoff", "id"); =20 - if (!optUUID && !optName) + if (!optUUID && !optName && !optID) optTable =3D true; =20 if (!(list =3D virshDomainListCollect(ctl, flags))) @@ -2007,6 +2016,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd) } =20 for (i =3D 0; i < list->ndomains; i++) { + const char *sep =3D ""; + dom =3D list->domains[i]; id =3D virDomainGetID(dom); if (id !=3D (unsigned int) -1) @@ -2044,20 +2055,24 @@ cmdList(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - } else if (optUUID && optName) { - if (virDomainGetUUIDString(dom, uuid) < 0) { - vshError(ctl, "%s", _("Failed to get domain's UUID")); - goto cleanup; + } else { + if (optUUID) { + if (virDomainGetUUIDString(dom, uuid) < 0) { + vshError(ctl, "%s", _("Failed to get domain's UUID")); + goto cleanup; + } + vshPrint(ctl, "%s", uuid); + sep =3D " "; } - vshPrint(ctl, "%-36s %-30s\n", uuid, virDomainGetName(dom)); - } else if (optUUID) { - if (virDomainGetUUIDString(dom, uuid) < 0) { - vshError(ctl, "%s", _("Failed to get domain's UUID")); - goto cleanup; + if (optID) { + vshPrint(ctl, "%s%s", sep, id_buf); + sep =3D " "; } - vshPrint(ctl, "%s\n", uuid); - } else if (optName) { - vshPrint(ctl, "%s\n", virDomainGetName(dom)); + if (optName) { + vshPrint(ctl, "%s%s", sep, virDomainGetName(dom)); + sep =3D " "; + } + vshPrint(ctl, "\n"); } } =20 --=20 2.26.2