From: Peter Krempa <pkrempa@redhat.com> Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/manpages/virsh.rst | 19 ++++++++++++++++++ tools/virsh-host.c | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 80b0ea14a8..01e2ac9d32 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1097,6 +1097,25 @@ on the host are reported. The option *--all* will report every CPU model known to the hypervisor, including ones that are not supported on the hypervisor (e.g. newer generation models). +introspection +------------- + +**Syntax:** + +:: + + introspection [--xpath EXPRESSION] [--wrap] + +Output the libvirt connection feature introspection XML. + +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. + + DOMAIN COMMANDS =============== diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ef91e22fed..e1980bc276 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1864,6 +1864,43 @@ cmdHypervisorCPUModelNames(vshControl *ctl, } +static const vshCmdInfo info_introspection = { + .help = N_("get XML containing connection introspection data"), + .desc = N_("get XML containing connection introspection data"), +}; + +static const vshCmdOptDef opts_introspection[] = { + {.name = "xpath", + .type = VSH_OT_STRING, + .completer = vshCompleteEmpty, + .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 +cmdIntrospection(vshControl *ctl, + const vshCmd *cmd) +{ + g_autofree char *xml = NULL; + virshControl *priv = ctl->privData; + bool wrap = vshCommandOptBool(cmd, "wrap"); + const char *xpath = NULL; + + if (vshCommandOptStringQuiet(ctl, cmd, "xpath", &xpath) < 0) + return false; + + if (!(xml = virConnectGetIntrospection(priv->conn, 0))) + return false; + + return virshDumpXML(ctl, xml, "domain", xpath, wrap); +} + + const vshCmdDef hostAndHypervisorCmds[] = { {.name = "allocpages", .handler = cmdAllocpages, @@ -2003,5 +2040,11 @@ const vshCmdDef hostAndHypervisorCmds[] = { .info = &info_version, .flags = 0 }, + {.name = "introspection", + .handler = cmdIntrospection, + .opts = opts_introspection, + .info = &info_introspection, + .flags = 0 + }, {.name = NULL} }; -- 2.54.0