virsh: add nodedev-autostart

Add ability to set node devices to autostart on boot or parent device
availability.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Jonathon Jongsma 2021-05-27 16:20:13 -05:00
parent 592031a580
commit 16d078eded
2 changed files with 86 additions and 0 deletions

View File

@ -5131,6 +5131,21 @@ When *--timestamp* is used, a human-readable timestamp will be printed
before the event.
nodedev-autostart
-----------------
**Syntax:**
::
nodedev-autostart [--disable] device
Configure a device to be automatically started when the host machine boots or
the parent device becomes available. With *--disable*, the device will be set
to manual mode and will no longer be automatically started by the host. This
command is only supported for persistently-defined mediated devices.
VIRTUAL NETWORK COMMANDS
========================

View File

@ -1153,6 +1153,71 @@ cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd)
}
/*
* "nodedev-autostart" command
*/
static const vshCmdInfo info_node_device_autostart[] = {
{.name = "help",
.data = N_("autostart a defined node device")
},
{.name = "desc",
.data = N_("Configure a node device to be automatically started at boot.")
},
{.name = NULL}
};
static const vshCmdOptDef opts_node_device_autostart[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("device name or wwn pair in 'wwnn,wwpn' format"),
.completer = virshNodeDeviceNameCompleter,
},
{.name = "disable",
.type = VSH_OT_BOOL,
.help = N_("disable autostarting")
},
{.name = NULL}
};
static bool
cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
{
virNodeDevice *dev = NULL;
bool ret = false;
const char *name = NULL;
int autostart;
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
return false;
dev = vshFindNodeDevice(ctl, name);
if (!dev) goto cleanup;
autostart = !vshCommandOptBool(cmd, "disable");
if (virNodeDeviceSetAutostart(dev, autostart) < 0) {
if (autostart)
vshError(ctl, _("failed to mark device %s as autostarted"), name);
else
vshError(ctl, _("failed to unmark device %s as autostarted"), name);
goto cleanup;
}
if (autostart)
vshPrintExtra(ctl, _("Device %s marked as autostarted\n"), name);
else
vshPrintExtra(ctl, _("Device %s unmarked as autostarted\n"), name);
ret = true;
cleanup:
if (dev)
virNodeDeviceFree(dev);
return ret;
}
const vshCmdDef nodedevCmds[] = {
{.name = "nodedev-create",
.handler = cmdNodeDeviceCreate,
@ -1224,5 +1289,11 @@ const vshCmdDef nodedevCmds[] = {
.info = info_node_device_start,
.flags = 0
},
{.name = "nodedev-autostart",
.handler = cmdNodeDeviceAutostart,
.opts = opts_node_device_autostart,
.info = info_node_device_autostart,
.flags = 0
},
{.name = NULL}
};