virsh: add support for '--validate' option in create network

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-09-15 13:07:31 +02:00 committed by Michal Privoznik
parent f6b83df5b3
commit 4d31c02f05
2 changed files with 15 additions and 2 deletions

View 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
----------

View 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,14 +211,21 @@ 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;
if (flags)
network = virNetworkCreateXMLFlags(priv->conn, buffer, flags);
else
network = virNetworkCreateXML(priv->conn, buffer);
if (network != NULL) {