]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Introduce --xpath and --wrap to capabilities
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 14 Apr 2023 14:01:56 +0000 (16:01 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 18 Apr 2023 06:37:23 +0000 (08:37 +0200)
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 <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
docs/manpages/virsh.rst
tools/virsh-host.c

index 26c328d39001c7cb59ca685f0c5bfe05b742d8cc..279e8e103e3e09f6d400d2fd916afd05b4305472 100644 (file)
@@ -541,7 +541,7 @@ capabilities
 
 ::
 
-   capabilities
+   capabilities [--xpath EXPRESSION] [--wrap]
 
 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:
 
 The XML also show the NUMA topology information if available.
 
+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.
+
 
 domcapabilities
 ---------------
index 4df599afdf08fcdf7c0bde27da5b5b9b0e75103c..1504eab0f1e024de9735a45a3871bb0651fde7d4 100644 (file)
@@ -32,6 +32,7 @@
 #include "virstring.h"
 #include "virfile.h"
 #include "virenum.h"
+#include "virsh-util.h"
 
 /*
  * "capabilities" command
@@ -43,22 +44,40 @@ static const vshCmdInfo info_capabilities[] = {
     {.name = "desc",
      .data = N_("Returns capabilities of hypervisor/driver.")
     },
+   {.name = NULL}
+};
+
+static const vshCmdOptDef opts_capabilities[] = {
+    {.name = "xpath",
+     .type = VSH_OT_STRING,
+     .flags = VSH_OFLAG_REQ_OPT,
+     .completer = virshCompleteEmpty,
+     .help = N_("xpath expression to filter the XML document")
+    },
+    {.name = "wrap",
+     .type = VSH_OT_BOOL,
+     .help = N_("wrap xpath results in an common root element"),
+    },
     {.name = NULL}
 };
 
 static bool
-cmdCapabilities(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
+cmdCapabilities(vshControl *ctl, const vshCmd *cmd)
 {
     g_autofree char *caps = NULL;
     virshControl *priv = ctl->privData;
+    bool wrap = vshCommandOptBool(cmd, "wrap");
+    const char *xpath = NULL;
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "xpath", &xpath) < 0)
+        return false;
 
     if ((caps = virConnectGetCapabilities(priv->conn)) == NULL) {
         vshError(ctl, "%s", _("failed to get capabilities"));
         return false;
     }
-    vshPrint(ctl, "%s\n", caps);
 
-    return true;
+    return virshDumpXML(ctl, caps, "capabilities", xpath, wrap);
 }
 
 /*
@@ -1785,7 +1804,7 @@ const vshCmdDef hostAndHypervisorCmds[] = {
     },
     {.name = "capabilities",
      .handler = cmdCapabilities,
-     .opts = NULL,
+     .opts = opts_capabilities,
      .info = info_capabilities,
      .flags = 0
     },