On 12/24/18 3:59 PM, Daniel P. Berrangé wrote: > Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> > --- > tools/virsh-completer.c | 51 +++++ > tools/virsh-completer.h | 4 + > tools/virsh-network.c | 399 +++++++++++++++++++++++++++++++++++++++- > tools/virsh-network.h | 5 + > 4 files changed, 458 insertions(+), 1 deletion(-) > > diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c > index cfbfeae328..e9ff09b696 100644 > --- a/tools/virsh-completer.c > +++ b/tools/virsh-completer.c > @@ -22,6 +22,7 @@ > > #include "virsh-completer.h" > #include "virsh-domain.h" > +#include "virsh-network.h" > #include "virsh.h" > #include "virsh-pool.h" > #include "virsh-nodedev.h" > @@ -382,6 +383,56 @@ virshNetworkNameCompleter(vshControl *ctl, > } > > > +char ** > +virshNetworkPortUUIDCompleter(vshControl *ctl, > + const vshCmd *cmd ATTRIBUTE_UNUSED, > + unsigned int flags) > +{ > + virshControlPtr priv = ctl->privData; > + virNetworkPtr net = NULL; > + virNetworkPortPtr *ports = NULL; > + int nports = 0; > + size_t i = 0; > + char **ret = NULL; > + > + virCheckFlags(0, NULL); > + > + if (!priv->conn || virConnectIsAlive(priv->conn) <= 0) > + return NULL; > + > + if (!(net = virshCommandOptNetwork(ctl, cmd, NULL))) > + return false; s/false/NULL/ > + > + if ((nports = virNetworkListAllPorts(net, &ports, flags)) < 0) > + return NULL; > + > + if (VIR_ALLOC_N(ret, nports + 1) < 0) > + goto error; > + > + for (i = 0; i < nports; i++) { > + char uuid[VIR_UUID_STRING_BUFLEN]; > + > + if (virNetworkPortGetUUIDString(ports[i], uuid) < 0 || > + VIR_STRDUP(ret[i], uuid) < 0) > + goto error; > + > + virNetworkPortFree(ports[i]); > + } > + VIR_FREE(ports); > + > + return ret; > + > + error: > + for (; i < nports; i++) > + virNetworkPortFree(ports[i]); > + VIR_FREE(ports); > + for (i = 0; i < nports; i++) > + VIR_FREE(ret[i]); > + VIR_FREE(ret); > + return NULL; > +} Kudos for implementing completer. Michal -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list