[PATCH 2/3] virsh: add support for '--validate' option in define interface

Kristina Hanicova khanicov at redhat.com
Fri Aug 6 13:08:15 UTC 2021


Signed-off-by: Kristina Hanicova <khanicov at redhat.com>
---
 include/libvirt/libvirt-interface.h |  4 ++++
 tools/virsh-interface.c             | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt-interface.h b/include/libvirt/libvirt-interface.h
index 7591c6c7fb..e849699230 100644
--- a/include/libvirt/libvirt-interface.h
+++ b/include/libvirt/libvirt-interface.h
@@ -79,6 +79,10 @@ typedef enum {
     VIR_INTERFACE_XML_INACTIVE = 1 << 0 /* dump inactive interface information */
 } virInterfaceXMLFlags;
 
+typedef enum {
+    VIR_INTERFACE_DEFINE_VALIDATE = (1 << 0), /* Validate the XML document against schema */
+} virInterfaceDefineFlags;
+
 char *                  virInterfaceGetXMLDesc    (virInterfacePtr iface,
                                                    unsigned int flags);
 virInterfacePtr         virInterfaceDefineXML     (virConnectPtr conn,
diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c
index 41acae5dcb..f72d40baab 100644
--- a/tools/virsh-interface.c
+++ b/tools/virsh-interface.c
@@ -525,6 +525,10 @@ static const vshCmdInfo info_interface_define[] = {
 
 static const vshCmdOptDef opts_interface_define[] = {
     VIRSH_COMMON_OPT_FILE(N_("file containing an XML interface description")),
+    {.name = "validate",
+     .type = VSH_OT_BOOL,
+     .help = N_("validate the XML against the schema")
+    },
     {.name = NULL}
 };
 
@@ -535,15 +539,19 @@ cmdInterfaceDefine(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_INTERFACE_DEFINE_VALIDATE;
+
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    iface = virInterfaceDefineXML(priv->conn, buffer, 0);
+    iface = virInterfaceDefineXML(priv->conn, buffer, flags);
     VIR_FREE(buffer);
 
     if (iface != NULL) {
-- 
2.31.1




More information about the libvir-list mailing list