summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristina Hanicova <khanicov@redhat.com>2021-08-23 18:50:14 +0200
committerMichal Privoznik <mprivozn@redhat.com>2021-08-24 15:47:03 +0200
commit7e7747cc2df14f41ab5711b488372fd4ae972a22 (patch)
treefe4e013de6a1a3b5a59e7946d8994ec94e756849
parentcc195a2da602f448a89e296ffa625351e41b97b9 (diff)
downloadlibvirt-7e7747cc2df14f41ab5711b488372fd4ae972a22.tar.gz
virsh: add support for '--validate' option in define network
Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
-rw-r--r--docs/manpages/virsh.rst4
-rw-r--r--tools/virsh-network.c13
2 files changed, 15 insertions, 2 deletions
diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index e0cdabf3aa..850a862fd9 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -5177,10 +5177,12 @@ net-define
::
- net-define file
+ net-define file [--validate]
Define an inactive persistent virtual network or modify an existing persistent
one from the XML *file*.
+Optionally, the format of the input XML file can be validated against an
+internal RNG schema with *--validate*.
net-destroy
diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 0d61e20093..badbcd0a92 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -244,6 +244,10 @@ static const vshCmdInfo info_network_define[] = {
static const vshCmdOptDef opts_network_define[] = {
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}
};
@@ -254,15 +258,22 @@ cmdNetworkDefine(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_DEFINE_VALIDATE;
+
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
- network = virNetworkDefineXML(priv->conn, buffer);
+ if (flags)
+ network = virNetworkDefineXMLFlags(priv->conn, buffer, flags);
+ else
+ network = virNetworkDefineXML(priv->conn, buffer);
if (network != NULL) {
vshPrintExtra(ctl, _("Network %s defined from %s\n"),