[PATCH 4/4] virsh: add support for '--validate' option in create nwfilter-binding

Kristina Hanicova khanicov at redhat.com
Thu Aug 26 12:32:35 UTC 2021


Signed-off-by: Kristina Hanicova <khanicov at redhat.com>
---
 docs/manpages/virsh.rst |  5 ++++-
 tools/virsh-nwfilter.c  | 10 +++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 2204bed3bb..15ac75d487 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -7586,7 +7586,7 @@ nwfilter-binding-create
 
 ::
 
-   nwfilter-binding-create xmlfile
+   nwfilter-binding-create xmlfile [--validate]
 
 Associate a network port with a network filter. The network filter backend
 will immediately attempt to instantiate the filter rules on the port. This
@@ -7597,6 +7597,9 @@ command to define a filter for a network port and then starting the guest
 afterwards may prevent the guest from starting if it attempts to use the
 network port and finds a filter already defined.
 
+Optionally, the format of the input XML file can be validated against an
+internal RNG schema with *--validate*.
+
 
 nwfilter-binding-delete
 -----------------------
diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c
index e062aa1649..77f211d031 100644
--- a/tools/virsh-nwfilter.c
+++ b/tools/virsh-nwfilter.c
@@ -503,6 +503,10 @@ static const vshCmdInfo info_nwfilter_binding_create[] = {
 static const vshCmdOptDef opts_nwfilter_binding_create[] = {
     VIRSH_COMMON_OPT_FILE(N_("file containing an XML network "
                              "filter binding description")),
+    {.name = "validate",
+     .type = VSH_OT_BOOL,
+     .help = N_("validate the XML against the schema")
+    },
     {.name = NULL}
 };
 
@@ -513,15 +517,19 @@ cmdNWFilterBindingCreate(vshControl *ctl, const vshCmd *cmd)
     const char *from = NULL;
     bool ret = true;
     char *buffer;
+    unsigned int flags = 0;
     virshControl *priv = ctl->privData;
 
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         return false;
 
+    if (vshCommandOptBool(cmd, "validate"))
+        flags |= VIR_NWFILTER_BINDING_CREATE_VALIDATE;
+
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    binding = virNWFilterBindingCreateXML(priv->conn, buffer, 0);
+    binding = virNWFilterBindingCreateXML(priv->conn, buffer, flags);
     VIR_FREE(buffer);
 
     if (binding != NULL) {
-- 
2.31.1




More information about the libvir-list mailing list