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(a)redhat.com>
---
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
::
- 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
---------------
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"
/*
* "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
},
--
2.39.2