[libvirt] [PATCH 16/18] virsh: Introduce virshDomainNameCompleter

Martin Kletzander mkletzan at redhat.com
Thu Jan 11 10:51:03 UTC 2018


On Tue, Jan 02, 2018 at 06:12:09PM +0100, Michal Privoznik wrote:
>Now that we have everything prepared let the fun begin. This
>completer is very simple and returns domain names. Moreover,
>depending on the command it can return just a subset of domains
>(e.g. only running/paused/transient/.. ones).
>
>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> tools/Makefile.am            |   9 +++
> tools/virsh-completer.c      |  90 +++++++++++++++++++++
> tools/virsh-completer.h      |  33 ++++++++
> tools/virsh-domain-monitor.c |  30 +++----
> tools/virsh-domain.c         | 182 ++++++++++++++++++++++---------------------
> tools/virsh-snapshot.c       |  24 +++---
> tools/virsh.h                |   7 +-
> 7 files changed, 256 insertions(+), 119 deletions(-)
> create mode 100644 tools/virsh-completer.c
> create mode 100644 tools/virsh-completer.h
>
>diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
>new file mode 100644
>index 000000000..4e32b882b
>--- /dev/null
>+++ b/tools/virsh-completer.c
>@@ -0,0 +1,90 @@
>+/*
>+ * virsh-completer.c: virsh completer callbacks
>+ *
>+ * Copyright (C) 2017 Red Hat, Inc.
>+ *
>+ * This library is free software; you can redistribute it and/or
>+ * modify it under the terms of the GNU Lesser General Public
>+ * License as published by the Free Software Foundation; either
>+ * version 2.1 of the License, or (at your option) any later version.
>+ *
>+ * This library is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this library.  If not, see
>+ * <http://www.gnu.org/licenses/>.
>+ *
>+ *  Michal Privoznik <mprivozn at redhat.com>

These two spaces before the name with no indication what the name means (like
"Authors" that we have in other files) makes me wonder why do we have names here
and there. Publicity?

>+ *
>+ */
>+
>+#include <config.h>
>+
>+#include "virsh-completer.h"
>+#include "virsh.h"
>+#include "virsh-util.h"
>+#include "internal.h"
>+#include "viralloc.h"
>+#include "virstring.h"
>+
>+
>+char **
>+virshDomainNameCompleter(vshControl *ctl,
>+                         const vshCmd *cmd ATTRIBUTE_UNUSED,
>+                         unsigned int flags)
>+{
>+    virshControlPtr priv = ctl->privData;
>+    virDomainPtr *domains = NULL;
>+    int ndomains = 0;
>+    size_t i = 0;
>+    char **ret = NULL;
>+
>+    virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
>+                  VIR_CONNECT_LIST_DOMAINS_INACTIVE |
>+                  VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
>+                  VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
>+                  VIR_CONNECT_LIST_DOMAINS_RUNNING |
>+                  VIR_CONNECT_LIST_DOMAINS_PAUSED |
>+                  VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
>+                  VIR_CONNECT_LIST_DOMAINS_OTHER |
>+                  VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE |
>+                  VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE |
>+                  VIR_CONNECT_LIST_DOMAINS_AUTOSTART |
>+                  VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART |
>+                  VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
>+                  VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT,
>+                  NULL);
>+
>+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
>+        return NULL;
>+
>+    if ((ndomains = virConnectListAllDomains(priv->conn, &domains, flags)) < 0)
>+        return NULL;
>+
>+    if (VIR_ALLOC_N(ret, ndomains + 1) < 0)
>+        goto error;
>+
>+    for (i = 0; i < ndomains; i++) {
>+        const char *name = virDomainGetName(domains[i]);
>+
>+        if (VIR_STRDUP(ret[i], name) < 0)
>+            goto error;
>+
>+        virshDomainFree(domains[i]);
>+    }
>+    VIR_FREE(domains);
>+
>+    return ret;
>+ error:
>+

Weird whitespace, I guess the label should've been one line lower.

I know, just bikeshedding.  Nothing against this patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180111/ef106de2/attachment-0001.sig>


More information about the libvir-list mailing list