]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: add support for '--validate' option in define network
authorKristina Hanicova <khanicov@redhat.com>
Mon, 23 Aug 2021 16:50:14 +0000 (18:50 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 24 Aug 2021 13:47:03 +0000 (15:47 +0200)
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/manpages/virsh.rst
tools/virsh-network.c

index e0cdabf3aa5bf12dce1b7ffdc542f79cac0fb54f..850a862fd9bc768aef4a9956884f9d5f40ea1bd0 100644 (file)
@@ -5177,10 +5177,12 @@ net-define
 
 ::
 
-   net-define file
+   net-define file [--validate]
 
 Define an inactive persistent virtual network or modify an existing persistent
 one from the XML *file*.
+Optionally, the format of the input XML file can be validated against an
+internal RNG schema with *--validate*.
 
 
 net-destroy
index 0d61e20093f45e6be2c9cd67aa8ef59b34bf5c4d..badbcd0a92afa751092665681af70dc6ead87a0b 100644 (file)
@@ -244,6 +244,10 @@ static const vshCmdInfo info_network_define[] = {
 
 static const vshCmdOptDef opts_network_define[] = {
     VIRSH_COMMON_OPT_FILE(N_("file containing an XML network description")),
+    {.name = "validate",
+     .type = VSH_OT_BOOL,
+     .help = N_("validate the XML against the schema")
+    },
     {.name = NULL}
 };
 
@@ -254,15 +258,22 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
     const char *from = NULL;
     bool ret = true;
     g_autofree char *buffer = NULL;
+    unsigned int flags = 0;
     virshControl *priv = ctl->privData;
 
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         return false;
 
+    if (vshCommandOptBool(cmd, "validate"))
+        flags |= VIR_NETWORK_DEFINE_VALIDATE;
+
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    network = virNetworkDefineXML(priv->conn, buffer);
+    if (flags)
+        network = virNetworkDefineXMLFlags(priv->conn, buffer, flags);
+    else
+        network = virNetworkDefineXML(priv->conn, buffer);
 
     if (network != NULL) {
         vshPrintExtra(ctl, _("Network %s defined from %s\n"),