mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
virsh: Add network uuid completion to network-name command
Signed-off-by: Lin Ma <lma@suse.de> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
d9a320bf97
commit
f6e69f03e3
@ -137,3 +137,45 @@ virshNetworkPortUUIDCompleter(vshControl *ctl,
|
||||
VIR_FREE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char **
|
||||
virshNetworkUUIDCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd G_GNUC_UNUSED,
|
||||
unsigned int flags)
|
||||
{
|
||||
virshControlPtr priv = ctl->privData;
|
||||
virNetworkPtr *nets = NULL;
|
||||
int nnets = 0;
|
||||
size_t i = 0;
|
||||
char **ret = NULL;
|
||||
VIR_AUTOSTRINGLIST tmp = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
|
||||
return NULL;
|
||||
|
||||
if ((nnets = virConnectListAllNetworks(priv->conn, &nets, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(tmp, nnets + 1) < 0)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < nnets; i++) {
|
||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||
|
||||
if (virNetworkGetUUIDString(nets[i], uuid) < 0)
|
||||
goto cleanup;
|
||||
|
||||
tmp[i] = g_strdup(uuid);
|
||||
}
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < nnets; i++)
|
||||
virNetworkFree(nets[i]);
|
||||
VIR_FREE(nets);
|
||||
return ret;
|
||||
}
|
||||
|
@ -33,3 +33,7 @@ char ** virshNetworkEventNameCompleter(vshControl *ctl,
|
||||
char ** virshNetworkPortUUIDCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
char ** virshNetworkUUIDCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
@ -806,6 +806,7 @@ static const vshCmdOptDef opts_network_name[] = {
|
||||
{.name = "network",
|
||||
.type = VSH_OT_DATA,
|
||||
.flags = VSH_OFLAG_REQ,
|
||||
.completer = virshNetworkUUIDCompleter,
|
||||
.help = N_("network uuid")
|
||||
},
|
||||
{.name = NULL}
|
||||
|
Loading…
x
Reference in New Issue
Block a user