The virConnectListAllNWFilters() has no extra flags yet, which
simplifies things a bit.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tools/virsh-completer.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
tools/virsh-completer.h | 4 ++++
tools/virsh-nwfilter.c | 9 ++++++---
3 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index c50143142..9e6f086c0 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -393,3 +393,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;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index 19fa2113d..3c3b17f1e 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -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
diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c
index 40bc193ad..06a002dff 100644
--- a/tools/virsh-nwfilter.c
+++ b/tools/virsh-nwfilter.c
@@ -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}
};
--
2.13.6