virsh: Introduce virshNodeDeviceNameCompleter

Yet again, we don't need listing by device capabilities, so flags
are unused.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Michal Privoznik 2018-01-12 14:44:37 +01:00
parent 7bed1a5b61
commit 4cdce24348
3 changed files with 60 additions and 5 deletions

View File

@ -342,3 +342,48 @@ virshNetworkNameCompleter(vshControl *ctl,
VIR_FREE(ret);
return NULL;
}
char **
virshNodeDeviceNameCompleter(vshControl *ctl,
const vshCmd *cmd ATTRIBUTE_UNUSED,
unsigned int flags)
{
virshControlPtr priv = ctl->privData;
virNodeDevicePtr *devs = NULL;
int ndevs = 0;
size_t i = 0;
char **ret = NULL;
virCheckFlags(0, NULL);
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
return NULL;
if ((ndevs = virConnectListAllNodeDevices(priv->conn, &devs, flags)) < 0)
return NULL;
if (VIR_ALLOC_N(ret, ndevs + 1) < 0)
goto error;
for (i = 0; i < ndevs; i++) {
const char *name = virNodeDeviceGetName(devs[i]);
if (VIR_STRDUP(ret[i], name) < 0)
goto error;
virNodeDeviceFree(devs[i]);
}
VIR_FREE(devs);
return ret;
error:
for (; i < ndevs; i++)
virNodeDeviceFree(devs[i]);
VIR_FREE(devs);
for (i = 0; i < ndevs; i++)
VIR_FREE(ret[i]);
VIR_FREE(ret);
return NULL;
}

View File

@ -54,4 +54,8 @@ char ** virshNetworkNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshNodeDeviceNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
#endif

View File

@ -109,7 +109,8 @@ static const vshCmdOptDef opts_node_device_destroy[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("device name or wwn pair in 'wwnn,wwpn' format")
.help = N_("device name or wwn pair in 'wwnn,wwpn' format"),
.completer = virshNodeDeviceNameCompleter,
},
{.name = NULL}
};
@ -534,6 +535,7 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = {
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("device name or wwn pair in 'wwnn,wwpn' format"),
.completer = virshNodeDeviceNameCompleter,
},
{.name = NULL}
};
@ -604,7 +606,8 @@ static const vshCmdOptDef opts_node_device_detach[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("device key")
.help = N_("device key"),
.completer = virshNodeDeviceNameCompleter,
},
{.name = "driver",
.type = VSH_OT_STRING,
@ -670,7 +673,8 @@ static const vshCmdOptDef opts_node_device_reattach[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("device key")
.help = N_("device key"),
.completer = virshNodeDeviceNameCompleter,
},
{.name = NULL}
};
@ -720,7 +724,8 @@ static const vshCmdOptDef opts_node_device_reset[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("device key")
.help = N_("device key"),
.completer = virshNodeDeviceNameCompleter,
},
{.name = NULL}
};
@ -866,7 +871,8 @@ static const vshCmdInfo info_node_device_event[] = {
static const vshCmdOptDef opts_node_device_event[] = {
{.name = "device",
.type = VSH_OT_STRING,
.help = N_("filter by node device name")
.help = N_("filter by node device name"),
.completer = virshNodeDeviceNameCompleter,
},
{.name = "event",
.type = VSH_OT_STRING,