virsh: add support for '--validate' option in create nwfilter-binding

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:32:35 +02:00 committed by Ján Tomko
parent 39f835621a
commit 8f8eeb3750
2 changed files with 13 additions and 2 deletions

View File

@ -7588,7 +7588,7 @@ nwfilter-binding-create
:: ::
nwfilter-binding-create xmlfile nwfilter-binding-create xmlfile [--validate]
Associate a network port with a network filter. The network filter backend Associate a network port with a network filter. The network filter backend
will immediately attempt to instantiate the filter rules on the port. This will immediately attempt to instantiate the filter rules on the port. This
@ -7599,6 +7599,9 @@ command to define a filter for a network port and then starting the guest
afterwards may prevent the guest from starting if it attempts to use the afterwards may prevent the guest from starting if it attempts to use the
network port and finds a filter already defined. network port and finds a filter already defined.
Optionally, the format of the input XML file can be validated against an
internal RNG schema with *--validate*.
nwfilter-binding-delete nwfilter-binding-delete
----------------------- -----------------------

View File

@ -503,6 +503,10 @@ static const vshCmdInfo info_nwfilter_binding_create[] = {
static const vshCmdOptDef opts_nwfilter_binding_create[] = { static const vshCmdOptDef opts_nwfilter_binding_create[] = {
VIRSH_COMMON_OPT_FILE(N_("file containing an XML network " VIRSH_COMMON_OPT_FILE(N_("file containing an XML network "
"filter binding description")), "filter binding description")),
{.name = "validate",
.type = VSH_OT_BOOL,
.help = N_("validate the XML against the schema")
},
{.name = NULL} {.name = NULL}
}; };
@ -513,15 +517,19 @@ cmdNWFilterBindingCreate(vshControl *ctl, const vshCmd *cmd)
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; char *buffer;
unsigned int flags = 0;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false; return false;
if (vshCommandOptBool(cmd, "validate"))
flags |= VIR_NWFILTER_BINDING_CREATE_VALIDATE;
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
binding = virNWFilterBindingCreateXML(priv->conn, buffer, 0); binding = virNWFilterBindingCreateXML(priv->conn, buffer, flags);
VIR_FREE(buffer); VIR_FREE(buffer);
if (binding != NULL) { if (binding != NULL) {