]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: add support for '--validate' option in create network
authorKristina Hanicova <khanicov@redhat.com>
Wed, 15 Sep 2021 11:07:31 +0000 (13:07 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 16 Sep 2021 14:26:18 +0000 (16:26 +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 ce98283ae32cdccffe133c176ee08f572735c1c7..48d6ab54df0f009de90cf567f2e6c354b92e1a47 100644 (file)
@@ -5189,13 +5189,15 @@ net-create
 
 ::
 
-   net-create file
+   net-create file [--validate]
 
 Create a transient (temporary) virtual network from an
 XML *file* and instantiate (start) the network.
 See the documentation at `https://libvirt.org/formatnetwork.html <https://libvirt.org/formatnetwork.html>`__
 to get a description of the XML network format used by libvirt.
 
+Optionally, the format of the input XML file can be validated against an
+internal RNG schema with *--validate*.
 
 net-define
 ----------
index a8f7f46905f2e42df7f979c68dc986dbfddc9f6f..37c19b663b57a5119992be87ce9cc371ea255dfa 100644 (file)
@@ -197,6 +197,10 @@ static const vshCmdInfo info_network_create[] = {
 
 static const vshCmdOptDef opts_network_create[] = {
     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}
 };
 
@@ -207,15 +211,22 @@ cmdNetworkCreate(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_CREATE_VALIDATE;
+
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    network = virNetworkCreateXML(priv->conn, buffer);
+    if (flags)
+        network = virNetworkCreateXMLFlags(priv->conn, buffer, flags);
+    else
+        network = virNetworkCreateXML(priv->conn, buffer);
 
     if (network != NULL) {
         vshPrintExtra(ctl, _("Network %s created from %s\n"),