From nobody Thu May 15 06:37:20 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510057413063168.0318209985146; Tue, 7 Nov 2017 04:23:33 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFCE75D9E2; Tue, 7 Nov 2017 12:23:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E80560561; Tue, 7 Nov 2017 12:23:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 58E5C3D383; Tue, 7 Nov 2017 12:23:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CNGvr031715 for ; Tue, 7 Nov 2017 07:23:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id E5CFD5C542; Tue, 7 Nov 2017 12:23:16 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D2705C545 for ; Tue, 7 Nov 2017 12:23:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AFCE75D9E2 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 7 Nov 2017 13:22:59 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/11] virt-admin: Introduce vshAdmServerCompleter X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Nov 2017 12:23:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- tools/Makefile.am | 9 ++++++ tools/virt-admin-completer.c | 76 ++++++++++++++++++++++++++++++++++++++++= ++++ tools/virt-admin-completer.h | 33 +++++++++++++++++++ tools/virt-admin.c | 8 +++++ 4 files changed, 126 insertions(+) create mode 100644 tools/virt-admin-completer.c create mode 100644 tools/virt-admin-completer.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 8eddc7bbe..a1652d459 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -261,6 +261,15 @@ virt_admin_SOURCES =3D \ virt-admin.c virt-admin.h \ $(NULL) =20 +VIRT_ADMIN_COMPLETER =3D \ + virt-admin-completer.c virt-admin-completer.h + +if WITH_READLINE +virt_admin_SOURCES +=3D $(VIRT_ADMIN_COMPLETER) +else ! WITH_READLINE +EXTRA_DIST +=3D $(VIRT_ADMIN_COMPLETER) +endif ! WITH_READLINE + virt_admin_LDFLAGS =3D \ $(AM_LDFLAGS) \ $(COVERAGE_LDFLAGS) \ diff --git a/tools/virt-admin-completer.c b/tools/virt-admin-completer.c new file mode 100644 index 000000000..2cd471f32 --- /dev/null +++ b/tools/virt-admin-completer.c @@ -0,0 +1,76 @@ +/* + * virt-admin-completer.c: virt-admin 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 + * . + * + * Michal Privoznik + * + */ + +#include + +#include "virt-admin-completer.h" +#include "internal.h" +#include "virt-admin.h" +#include "viralloc.h" +#include "virstring.h" + + +char ** +vshAdmServerCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + vshAdmControlPtr priv =3D ctl->privData; + virAdmServerPtr *srvs =3D NULL; + int nsrvs =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virAdmConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + /* Obtain a list of available servers on the daemon */ + if ((nsrvs =3D virAdmConnectListServers(priv->conn, &srvs, 0)) < 0) + return NULL; + + if (VIR_ALLOC_N(ret, nsrvs + 1) < 0) + goto error; + + for (i =3D 0; i < nsrvs; i++) { + const char *name =3D virAdmServerGetName(srvs[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virAdmServerFree(srvs[i]); + } + VIR_FREE(srvs); + + return ret; + + error: + for (; i < nsrvs; i++) + virAdmServerFree(srvs[i]); + VIR_FREE(srvs); + for (i =3D 0; i < nsrvs; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return ret; +} diff --git a/tools/virt-admin-completer.h b/tools/virt-admin-completer.h new file mode 100644 index 000000000..7507b95c1 --- /dev/null +++ b/tools/virt-admin-completer.h @@ -0,0 +1,33 @@ +/* + * virt-admin-completer.h: virt-admin 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 + * . + * + * Michal Privoznik + * + */ + +#ifndef VIRT_ADMIN_COMPLETER +# define VIRT_ADMIN_COMPLETER + +# include "vsh.h" + +char ** +vshAdmServerCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); +#endif diff --git a/tools/virt-admin.c b/tools/virt-admin.c index c24ed95c0..41b945e49 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -39,6 +39,7 @@ #include "virthread.h" #include "virgettext.h" #include "virtime.h" +#include "virt-admin-completer.h" =20 /* Gnulib doesn't guarantee SA_SIGINFO support. */ #ifndef SA_SIGINFO @@ -432,6 +433,7 @@ static const vshCmdOptDef opts_srv_threadpool_info[] = =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("Server to retrieve threadpool attributes from."), }, {.name =3D NULL} @@ -493,6 +495,7 @@ static const vshCmdOptDef opts_srv_threadpool_set[] =3D= { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("Server to alter threadpool attributes on."), }, {.name =3D "min-workers", @@ -599,6 +602,7 @@ static const vshCmdOptDef opts_srv_clients_list[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("server which to list connected clients from"), }, {.name =3D NULL} @@ -680,6 +684,7 @@ static const vshCmdOptDef opts_client_info[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("server to which is connected to"), }, {.name =3D "client", @@ -767,6 +772,7 @@ static const vshCmdOptDef opts_client_disconnect[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("server which the client is currently connected to"), }, {.name =3D "client", @@ -832,6 +838,7 @@ static const vshCmdOptDef opts_srv_clients_info[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("Server to retrieve the client limits from."), }, {.name =3D NULL} @@ -891,6 +898,7 @@ static const vshCmdOptDef opts_srv_clients_set[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("Server to alter the client-related configuration limits= on."), }, {.name =3D "max-clients", --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list