mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
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:
parent
7bed1a5b61
commit
4cdce24348
@ -342,3 +342,48 @@ virshNetworkNameCompleter(vshControl *ctl,
|
|||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
return NULL;
|
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,
|
const vshCmd *cmd,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
|
char ** virshNodeDeviceNameCompleter(vshControl *ctl,
|
||||||
|
const vshCmd *cmd,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -109,7 +109,8 @@ static const vshCmdOptDef opts_node_device_destroy[] = {
|
|||||||
{.name = "device",
|
{.name = "device",
|
||||||
.type = VSH_OT_DATA,
|
.type = VSH_OT_DATA,
|
||||||
.flags = VSH_OFLAG_REQ,
|
.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}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
@ -534,6 +535,7 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = {
|
|||||||
.type = VSH_OT_DATA,
|
.type = VSH_OT_DATA,
|
||||||
.flags = VSH_OFLAG_REQ,
|
.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}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
@ -604,7 +606,8 @@ static const vshCmdOptDef opts_node_device_detach[] = {
|
|||||||
{.name = "device",
|
{.name = "device",
|
||||||
.type = VSH_OT_DATA,
|
.type = VSH_OT_DATA,
|
||||||
.flags = VSH_OFLAG_REQ,
|
.flags = VSH_OFLAG_REQ,
|
||||||
.help = N_("device key")
|
.help = N_("device key"),
|
||||||
|
.completer = virshNodeDeviceNameCompleter,
|
||||||
},
|
},
|
||||||
{.name = "driver",
|
{.name = "driver",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
@ -670,7 +673,8 @@ static const vshCmdOptDef opts_node_device_reattach[] = {
|
|||||||
{.name = "device",
|
{.name = "device",
|
||||||
.type = VSH_OT_DATA,
|
.type = VSH_OT_DATA,
|
||||||
.flags = VSH_OFLAG_REQ,
|
.flags = VSH_OFLAG_REQ,
|
||||||
.help = N_("device key")
|
.help = N_("device key"),
|
||||||
|
.completer = virshNodeDeviceNameCompleter,
|
||||||
},
|
},
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
@ -720,7 +724,8 @@ static const vshCmdOptDef opts_node_device_reset[] = {
|
|||||||
{.name = "device",
|
{.name = "device",
|
||||||
.type = VSH_OT_DATA,
|
.type = VSH_OT_DATA,
|
||||||
.flags = VSH_OFLAG_REQ,
|
.flags = VSH_OFLAG_REQ,
|
||||||
.help = N_("device key")
|
.help = N_("device key"),
|
||||||
|
.completer = virshNodeDeviceNameCompleter,
|
||||||
},
|
},
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
@ -866,7 +871,8 @@ static const vshCmdInfo info_node_device_event[] = {
|
|||||||
static const vshCmdOptDef opts_node_device_event[] = {
|
static const vshCmdOptDef opts_node_device_event[] = {
|
||||||
{.name = "device",
|
{.name = "device",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
.help = N_("filter by node device name")
|
.help = N_("filter by node device name"),
|
||||||
|
.completer = virshNodeDeviceNameCompleter,
|
||||||
},
|
},
|
||||||
{.name = "event",
|
{.name = "event",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user