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

index 279e8e103e3e09f6d400d2fd916afd05b4305472..c3014f7b0682b210faa513847a75211862bb6136 100644 (file)
@@ -569,6 +569,7 @@ domcapabilities
 ::
 
    domcapabilities [virttype] [emulatorbin] [arch] [machine]
+                   [--xpath EXPRESSION] [--wrap]
 
 
 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.
 
+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.
+
 
 pool-capabilities
 -----------------
index 1504eab0f1e024de9735a45a3871bb0651fde7d4..0bda327cae2f4afc97960f593072f8b6f71ec9a2 100644 (file)
@@ -112,6 +112,16 @@ static const vshCmdOptDef opts_domcapabilities[] = {
      .type = VSH_OT_STRING,
      .help = N_("machine type (/domain/os/type/@machine)"),
     },
+    {.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}
 };
 
@@ -123,13 +133,16 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
     const char *emulatorbin = NULL;
     const char *arch = NULL;
     const char *machine = NULL;
+    const char *xpath = NULL;
     const unsigned int flags = 0; /* No flags so far */
+    bool wrap = vshCommandOptBool(cmd, "wrap");
     virshControl *priv = ctl->privData;
 
     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;
 
     caps = virConnectGetDomainCapabilities(priv->conn, emulatorbin,
@@ -139,9 +152,7 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    vshPrint(ctl, "%s\n", caps);
-
-    return true;
+    return virshDumpXML(ctl, caps, "domcapabilities", xpath, wrap);
 }
 
 /*