]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: add support for '--validate' option in create network port
authorKristina Hanicova <khanicov@redhat.com>
Thu, 26 Aug 2021 12:23:57 +0000 (14:23 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 6 Sep 2021 15:08:59 +0000 (17:08 +0200)
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
docs/manpages/virsh.rst
tools/virsh-network.c

index 2204bed3bb9e638cfb2752eee9862553d0de09ce..c699b198fb42625162c9f684413fe886209ec93c 100644 (file)
@@ -5452,10 +5452,12 @@ net-port-create
 
 ::
 
-   net-port-create network file
+   net-port-create network file [--validate]
 
 Allocate a new network port reserving resources based on the
 port description.
+Optionally, the format of the input XML file can be validated against an
+internal RNG schema with *--validate*.
 
 
 net-port-dumpxml
index badbcd0a92afa751092665681af70dc6ead87a0b..a8f7f46905f2e42df7f979c68dc986dbfddc9f6f 100644 (file)
@@ -1492,6 +1492,10 @@ static const vshCmdInfo info_network_port_create[] = {
 static const vshCmdOptDef opts_network_port_create[] = {
     VIRSH_COMMON_OPT_NETWORK_FULL(VIR_CONNECT_LIST_NETWORKS_ACTIVE),
     VIRSH_COMMON_OPT_FILE(N_("file containing an XML network port description")),
+    {.name = "validate",
+     .type = VSH_OT_BOOL,
+     .help = N_("validate the XML against the schema")
+    },
     {.name = NULL}
 };
 
@@ -1503,6 +1507,7 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     char *buffer = NULL;
     virNetworkPtr network = NULL;
+    unsigned int flags = 0;
 
     network = virshCommandOptNetwork(ctl, cmd, NULL);
     if (network == NULL)
@@ -1511,12 +1516,15 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         goto cleanup;
 
+    if (vshCommandOptBool(cmd, "validate"))
+        flags |= VIR_NETWORK_PORT_CREATE_VALIDATE;
+
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
         vshSaveLibvirtError();
         goto cleanup;
     }
 
-    port = virNetworkPortCreateXML(network, buffer, 0);
+    port = virNetworkPortCreateXML(network, buffer, flags);
 
     if (port != NULL) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];