Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx> --- docs/manpages/virsh.rst | 4 +++- tools/virsh-network.c | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 2204bed3bb..c699b198fb 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -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 diff --git a/tools/virsh-network.c b/tools/virsh-network.c index badbcd0a92..a8f7f46905 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -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]; -- 2.31.1