[PATCH 6/6] virsh: add support for '--validate' option in create network

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 docs/manpages/virsh.rst |  4 +++-
 tools/virsh-network.c   | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 2204bed3bb..b05b25c555 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -5162,13 +5162,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
 ----------
diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index badbcd0a92..eff9d153c4 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -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"),
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux