mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
virsh: Introduce virshNWFilterNameCompleter
The virConnectListAllNWFilters() has no extra flags yet, which simplifies things a bit. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
4cdce24348
commit
2ba76e5cc7
@ -387,3 +387,48 @@ virshNodeDeviceNameCompleter(vshControl *ctl,
|
||||
VIR_FREE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char **
|
||||
virshNWFilterNameCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd ATTRIBUTE_UNUSED,
|
||||
unsigned int flags)
|
||||
{
|
||||
virshControlPtr priv = ctl->privData;
|
||||
virNWFilterPtr *nwfilters = NULL;
|
||||
int nnwfilters = 0;
|
||||
size_t i = 0;
|
||||
char **ret = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
|
||||
return NULL;
|
||||
|
||||
if ((nnwfilters = virConnectListAllNWFilters(priv->conn, &nwfilters, flags)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(ret, nnwfilters + 1) < 0)
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < nnwfilters; i++) {
|
||||
const char *name = virNWFilterGetName(nwfilters[i]);
|
||||
|
||||
if (VIR_STRDUP(ret[i], name) < 0)
|
||||
goto error;
|
||||
|
||||
virNWFilterFree(nwfilters[i]);
|
||||
}
|
||||
VIR_FREE(nwfilters);
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
for (; i < nnwfilters; i++)
|
||||
virNWFilterFree(nwfilters[i]);
|
||||
VIR_FREE(nwfilters);
|
||||
for (i = 0; i < nnwfilters; i++)
|
||||
VIR_FREE(ret[i]);
|
||||
VIR_FREE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -58,4 +58,8 @@ char ** virshNodeDeviceNameCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
char ** virshNWFilterNameCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
#endif
|
||||
|
@ -136,7 +136,8 @@ static const vshCmdOptDef opts_nwfilter_undefine[] = {
|
||||
{.name = "nwfilter",
|
||||
.type = VSH_OT_DATA,
|
||||
.flags = VSH_OFLAG_REQ,
|
||||
.help = N_("network filter name or uuid")
|
||||
.help = N_("network filter name or uuid"),
|
||||
.completer = virshNWFilterNameCompleter,
|
||||
},
|
||||
{.name = NULL}
|
||||
};
|
||||
@ -179,7 +180,8 @@ static const vshCmdOptDef opts_nwfilter_dumpxml[] = {
|
||||
{.name = "nwfilter",
|
||||
.type = VSH_OT_DATA,
|
||||
.flags = VSH_OFLAG_REQ,
|
||||
.help = N_("network filter name or uuid")
|
||||
.help = N_("network filter name or uuid"),
|
||||
.completer = virshNWFilterNameCompleter,
|
||||
},
|
||||
{.name = NULL}
|
||||
};
|
||||
@ -396,7 +398,8 @@ static const vshCmdOptDef opts_nwfilter_edit[] = {
|
||||
{.name = "nwfilter",
|
||||
.type = VSH_OT_DATA,
|
||||
.flags = VSH_OFLAG_REQ,
|
||||
.help = N_("network filter name or uuid")
|
||||
.help = N_("network filter name or uuid"),
|
||||
.completer = virshNWFilterNameCompleter,
|
||||
},
|
||||
{.name = NULL}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user