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

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>
This commit is contained in:
Kristina Hanicova 2021-08-26 14:23:57 +02:00 committed by Ján Tomko
parent 652147d0e1
commit 6779fca41c
2 changed files with 12 additions and 2 deletions

View 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

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