Add a virsh command that maps to virNodeDeviceDefineXML().
Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
Reviewed-by: Erik Skultety <eskultet(a)redhat.com>
---
tools/virsh-nodedev.c | 58 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 7ab5b264fc..2ad676fc91 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -1013,6 +1013,58 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd)
}
+/*
+ * "nodedev-define" command
+ */
+static const vshCmdInfo info_node_device_define[] = {
+ {.name = "help",
+ .data = N_("Define a device by an xml file on a node")
+ },
+ {.name = "desc",
+ .data = N_("Defines a persistent device on the node that can be "
+ "assigned to a domain. The device must be started before "
+ "it can be assigned to a domain.")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_node_device_define[] = {
+ VIRSH_COMMON_OPT_FILE(N_("file containing an XML description "
+ "of the device")),
+ {.name = NULL}
+};
+
+static bool
+cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
+{
+ virNodeDevicePtr dev = NULL;
+ const char *from = NULL;
+ bool ret = true;
+ char *buffer;
+ virshControlPtr priv = ctl->privData;
+
+ if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
+ return false;
+
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
+ return false;
+
+ dev = virNodeDeviceDefineXML(priv->conn, buffer, 0);
+ VIR_FREE(buffer);
+
+ if (dev != NULL) {
+ vshPrintExtra(ctl, _("Node device '%s' defined from
'%s'\n"),
+ virNodeDeviceGetName(dev), from);
+ virNodeDeviceFree(dev);
+ } else {
+ vshError(ctl, _("Failed to define node device from '%s'"),
from);
+ ret = false;
+ }
+
+ return ret;
+}
+
+
const vshCmdDef nodedevCmds[] = {
{.name = "nodedev-create",
.handler = cmdNodeDeviceCreate,
@@ -1066,5 +1118,11 @@ const vshCmdDef nodedevCmds[] = {
.info = info_node_device_event,
.flags = 0
},
+ {.name = "nodedev-define",
+ .handler = cmdNodeDeviceDefine,
+ .opts = opts_node_device_define,
+ .info = info_node_device_define,
+ .flags = 0
+ },
{.name = NULL}
};
--
2.26.2