From nobody Thu Jun 13 12:20:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1681482311; cv=none; d=zohomail.com; s=zohoarc; b=GtGWER040r+Y70oTaUu2NunMfurc4xMynFwdDVH/+PVehKzpp3Drl/2GZYsEdc0gceh3tS+cbR15qZp7A1WZ1dpqu+lIevw4STROUkK1H1eBRjwSDduT2LfiuwL+HTG+ge4S0egslCmaM24krU+K3UAr14dCIxi3UVvyWsI3ZtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681482311; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WZo1VXeaphtJvBtJJD6EtAefvY3HG0CyVUoByQeLWuU=; b=JuXFsvWUZD8aP95GhkGlriHwpQ9ppazj5VcFTFI9zKEboZkSfqFDPEQuzx128fRZ7sQOrDyk3fN300U5VoW3ZSykdQN3ozBTOoVoPX7pegg/HZ+nVJK5rPk6ava9Zgcaz4kzNC/fBREe/r7QlfMN1YjQH6K//wvJOuHpzwRhcEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 168148231169929.92128061743358; Fri, 14 Apr 2023 07:25:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-642-T585d3zSPAezNug_asLnnA-1; Fri, 14 Apr 2023 10:23:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8ACF41C1742E; Fri, 14 Apr 2023 14:23:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77D3B2027047; Fri, 14 Apr 2023 14:23:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2E80219472CD; Fri, 14 Apr 2023 14:23:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A401319472C9 for ; Fri, 14 Apr 2023 14:23:45 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8A256492B01; Fri, 14 Apr 2023 14:23:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33562492B00 for ; Fri, 14 Apr 2023 14:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681482310; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=WZo1VXeaphtJvBtJJD6EtAefvY3HG0CyVUoByQeLWuU=; b=VBUa9AoyQ6+Cf5/3GOaNxZvnjpYPdfCDbdM/Js8alxJaGXHF0yV1XNBcgIOb3sMxQzsdEV 1KI1y46gxYm/r5VkbJ1cUxEx7hdwJJ6atFFdR+BFQEo01UYgftFVs9hL7NfQH1oOWd+Vp5 lQfacLUmn5fAHet61B1r5VDMp7UtKGg= X-MC-Unique: T585d3zSPAezNug_asLnnA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] virsh: Introduce --xpath and --wrap to capabilities Date: Fri, 14 Apr 2023 16:23:41 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681482312161100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Similarly to dumpxml, let's have --xpath and --wrap to the 'capabilities' command since users might be interested only in a subset of capabilities XML. Signed-off-by: Michal Privoznik Reviewed-by: Kristina Hanicova --- docs/manpages/virsh.rst | 9 ++++++++- tools/virsh-host.c | 27 +++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 26c328d390..279e8e103e 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -541,7 +541,7 @@ capabilities =20 :: =20 - capabilities + capabilities [--xpath EXPRESSION] [--wrap] =20 Print an XML document describing the capabilities of the hypervisor we are currently connected to. This includes a section on the host @@ -553,6 +553,13 @@ description see: =20 The XML also show the NUMA topology information if available. =20 +If the **--xpath** argument provides an XPath expression, it will be +evaluated against the output XML and only those matching nodes will +be printed. The default behaviour is to print each matching node as +a standalone document, however, for ease of additional processing, +the **--wrap** argument will cause the matching node to be wrapped +in a common root node. + =20 domcapabilities --------------- diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 4df599afdf..1504eab0f1 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -32,6 +32,7 @@ #include "virstring.h" #include "virfile.h" #include "virenum.h" +#include "virsh-util.h" =20 /* * "capabilities" command @@ -43,22 +44,40 @@ static const vshCmdInfo info_capabilities[] =3D { {.name =3D "desc", .data =3D N_("Returns capabilities of hypervisor/driver.") }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_capabilities[] =3D { + {.name =3D "xpath", + .type =3D VSH_OT_STRING, + .flags =3D VSH_OFLAG_REQ_OPT, + .completer =3D virshCompleteEmpty, + .help =3D N_("xpath expression to filter the XML document") + }, + {.name =3D "wrap", + .type =3D VSH_OT_BOOL, + .help =3D N_("wrap xpath results in an common root element"), + }, {.name =3D NULL} }; =20 static bool -cmdCapabilities(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) +cmdCapabilities(vshControl *ctl, const vshCmd *cmd) { g_autofree char *caps =3D NULL; virshControl *priv =3D ctl->privData; + bool wrap =3D vshCommandOptBool(cmd, "wrap"); + const char *xpath =3D NULL; + + if (vshCommandOptStringQuiet(ctl, cmd, "xpath", &xpath) < 0) + return false; =20 if ((caps =3D virConnectGetCapabilities(priv->conn)) =3D=3D NULL) { vshError(ctl, "%s", _("failed to get capabilities")); return false; } - vshPrint(ctl, "%s\n", caps); =20 - return true; + return virshDumpXML(ctl, caps, "capabilities", xpath, wrap); } =20 /* @@ -1785,7 +1804,7 @@ const vshCmdDef hostAndHypervisorCmds[] =3D { }, {.name =3D "capabilities", .handler =3D cmdCapabilities, - .opts =3D NULL, + .opts =3D opts_capabilities, .info =3D info_capabilities, .flags =3D 0 }, --=20 2.39.2 From nobody Thu Jun 13 12:20:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1681482242; cv=none; d=zohomail.com; s=zohoarc; b=NLO4nJZ1hGIViEh1YNHO58R45cc8B493JYcI/CVQPtuwxm9A/l5yeY18QjGopECeK4Y59negBaGQbEI/ShgcU7XVSyS2qOOn4zya2+T7ETqPQkmCkFL+v5Dh5GtIcSlbtoQpZ3r36YMltF9k7gPrt3Scflq8ICTHbatn771lfYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681482242; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZXpl+FR0gfrwTHdYzqi13uOUc/gFOiSvX/gtgEOBH5c=; b=oJP2cRFRgHRA64RpeE3tDs78y7zzevxVFS+fNVp1ExfgrwKFvnlZXXgxwFU/UqrmOIiJQqExSaoxEDhLjuqQbi8YnG6/pSNERl3zkKGI06zAV5gULHjEYVQK5mLLrBHx32yNCg721r8T40ZeID6FOf+4H8d42FH49QYWlmXI0Ew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1681482242880589.7100945823729; Fri, 14 Apr 2023 07:24:02 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-642-grqvqdCSMcWwEvUmXR66RQ-1; Fri, 14 Apr 2023 10:23:55 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BBCA6857FB3; Fri, 14 Apr 2023 14:23:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3D2F47CE1; Fri, 14 Apr 2023 14:23:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 733FF19472D0; Fri, 14 Apr 2023 14:23:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 326DF19472D8 for ; Fri, 14 Apr 2023 14:23:46 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 239AB492B01; Fri, 14 Apr 2023 14:23:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0B01492B00 for ; Fri, 14 Apr 2023 14:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681482242; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZXpl+FR0gfrwTHdYzqi13uOUc/gFOiSvX/gtgEOBH5c=; b=J9QNMUlQuZ7egfiPAVziMddP4yI5y9xxYemFy9RaltNjCNkNAajyMG3aWzK3VUUJiZAV/2 q4U+6fyRiCutGq6gQvILcfSC/G+HFcI/7AjF6MRuDKOBRcLBvepbLqkBjuDQlLy16r3GQK hMLgLNsmggx05bhcxHkulGCjW39+zls= X-MC-Unique: grqvqdCSMcWwEvUmXR66RQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] virsh: Introduce --xpath and --wrap to domcapabilities Date: Fri, 14 Apr 2023 16:23:42 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681482244101100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Similarly to dumpxml, let's have --xpath and --wrap to the 'domcapabilities' command since users might be interested only in a subset of domcapabilities XML. Signed-off-by: Michal Privoznik Reviewed-by: Kristina Hanicova --- docs/manpages/virsh.rst | 8 ++++++++ tools/virsh-host.c | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 279e8e103e..c3014f7b06 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -569,6 +569,7 @@ domcapabilities :: =20 domcapabilities [virttype] [emulatorbin] [arch] [machine] + [--xpath EXPRESSION] [--wrap] =20 =20 Print an XML document describing the domain capabilities for the @@ -603,6 +604,13 @@ supplied along with either the *emulatorbin* or *arch*= in order to generate output for the default *machine*. Supplying a *machine* value will generate output for the specific machine. =20 +If the **--xpath** argument provides an XPath expression, it will be +evaluated against the output XML and only those matching nodes will +be printed. The default behaviour is to print each matching node as +a standalone document, however, for ease of additional processing, +the **--wrap** argument will cause the matching node to be wrapped +in a common root node. + =20 pool-capabilities ----------------- diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 1504eab0f1..0bda327cae 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -112,6 +112,16 @@ static const vshCmdOptDef opts_domcapabilities[] =3D { .type =3D VSH_OT_STRING, .help =3D N_("machine type (/domain/os/type/@machine)"), }, + {.name =3D "xpath", + .type =3D VSH_OT_STRING, + .flags =3D VSH_OFLAG_REQ_OPT, + .completer =3D virshCompleteEmpty, + .help =3D N_("xpath expression to filter the XML document") + }, + {.name =3D "wrap", + .type =3D VSH_OT_BOOL, + .help =3D N_("wrap xpath results in an common root element"), + }, {.name =3D NULL} }; =20 @@ -123,13 +133,16 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) const char *emulatorbin =3D NULL; const char *arch =3D NULL; const char *machine =3D NULL; + const char *xpath =3D NULL; const unsigned int flags =3D 0; /* No flags so far */ + bool wrap =3D vshCommandOptBool(cmd, "wrap"); virshControl *priv =3D ctl->privData; =20 if (vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 || vshCommandOptStringReq(ctl, cmd, "emulatorbin", &emulatorbin) < 0 = || vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 || - vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0) + vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0 || + vshCommandOptStringQuiet(ctl, cmd, "xpath", &xpath) < 0) return false; =20 caps =3D virConnectGetDomainCapabilities(priv->conn, emulatorbin, @@ -139,9 +152,7 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) return false; } =20 - vshPrint(ctl, "%s\n", caps); - - return true; + return virshDumpXML(ctl, caps, "domcapabilities", xpath, wrap); } =20 /* --=20 2.39.2