提交 4cdce243 编写于 作者: M Michal Privoznik

virsh: Introduce virshNodeDeviceNameCompleter

Yet again, we don't need listing by device capabilities, so flags
are unused.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 7bed1a5b
......@@ -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;
}
......@@ -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
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册