diff options
author | Peter Krempa <pkrempa@redhat.com> | 2022-10-18 13:19:05 +0200 |
---|---|---|
committer | Peter Krempa <pkrempa@redhat.com> | 2022-11-01 13:07:20 +0100 |
commit | d8791c3c7caa6e3cadaf98a5a2c94b232ac30fed (patch) | |
tree | e61ef3ec777fcf2e7286fb46f76d99d65318d912 /tools | |
parent | 0268270b0f097cfca4219624daa31270a7cedf0f (diff) | |
download | libvirt-d8791c3c7caa6e3cadaf98a5a2c94b232ac30fed.tar.gz |
nodedev: Add VIR_NODE_DEVICE_(CREATE|DEFINE)_XML_VALIDATE flags
The node device APIs which get XML from the user don't yet support XML
validation flags. Introduce virNodeDeviceCreateXMLFlags and
virNodeDeviceDefineXMLFlags with the appropriate flags and add virsh
support for the new flags.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/virsh-nodedev.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 2adcad9c10..5dbec65367 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -50,6 +50,10 @@ static const vshCmdInfo info_node_device_create[] = { static const vshCmdOptDef opts_node_device_create[] = { VIRSH_COMMON_OPT_FILE(N_("file containing an XML description " "of the device")), + {.name = "validate", + .type = VSH_OT_BOOL, + .help = N_("validate the XML against the schema") + }, {.name = NULL} }; @@ -60,6 +64,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; + unsigned int flags = 0; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; @@ -67,7 +72,10 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; - if (!(dev = virNodeDeviceCreateXML(priv->conn, buffer, 0))) { + if (vshCommandOptBool(cmd, "validate")) + flags |= VIR_NODE_DEVICE_CREATE_XML_VALIDATE; + + if (!(dev = virNodeDeviceCreateXML(priv->conn, buffer, flags))) { vshError(ctl, _("Failed to create node device from %s"), from); return false; } @@ -1058,6 +1066,10 @@ static const vshCmdInfo info_node_device_define[] = { static const vshCmdOptDef opts_node_device_define[] = { VIRSH_COMMON_OPT_FILE(N_("file containing an XML description " "of the device")), + {.name = "validate", + .type = VSH_OT_BOOL, + .help = N_("validate the XML against the schema") + }, {.name = NULL} }; @@ -1068,6 +1080,7 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) const char *from = NULL; g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; + unsigned int flags = 0; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; @@ -1075,7 +1088,10 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; - if (!(dev = virNodeDeviceDefineXML(priv->conn, buffer, 0))) { + if (vshCommandOptBool(cmd, "validate")) + flags |= VIR_NODE_DEVICE_DEFINE_XML_VALIDATE; + + if (!(dev = virNodeDeviceDefineXML(priv->conn, buffer, flags))) { vshError(ctl, _("Failed to define node device from '%s'"), from); return false; } |