From nobody Thu May 15 03:37:35 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 1515768003239100.04693597592723; Fri, 12 Jan 2018 06:40:03 -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 EE9FE15DE; Fri, 12 Jan 2018 14:39:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D42718A4D; Fri, 12 Jan 2018 14:39:39 +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 5153C18033DE; Fri, 12 Jan 2018 14:39:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0CEbxRj025472 for ; Fri, 12 Jan 2018 09:37:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8FA5C6561F; Fri, 12 Jan 2018 14:37:59 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14F916560E for ; Fri, 12 Jan 2018 14:37:54 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 12 Jan 2018 15:37:37 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/8] virsh: Introduce virshInterfaceNameCompleter 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.29]); Fri, 12 Jan 2018 14:39:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tools/virsh-completer.c | 47 +++++++++++++++++++++++++++++++++++++++++++++= ++ tools/virsh-completer.h | 4 ++++ tools/virsh-interface.c | 16 +++++++++------- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index d6ac0ccb8..f5b1e4261 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -250,3 +250,50 @@ virshStorageVolNameCompleter(vshControl *ctl, virStoragePoolFree(pool); return NULL; } + + +char ** +virshInterfaceNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virInterfacePtr *ifaces =3D NULL; + int nifaces =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE | + VIR_CONNECT_LIST_INTERFACES_INACTIVE, + NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((nifaces =3D virConnectListAllInterfaces(priv->conn, &ifaces, flag= s)) < 0) + return NULL; + + if (VIR_ALLOC_N(ret, nifaces + 1) < 0) + goto error; + + for (i =3D 0; i < nifaces; i++) { + const char *name =3D virInterfaceGetName(ifaces[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virInterfaceFree(ifaces[i]); + } + VIR_FREE(ifaces); + + return ret; + + error: + for (; i < nifaces; i++) + virInterfaceFree(ifaces[i]); + VIR_FREE(ifaces); + for (i =3D 0; i < nifaces; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 1e4ce5932..2323aaba3 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -46,4 +46,8 @@ char ** virshStorageVolNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshInterfaceNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index c1a2b21de..50518c667 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -23,11 +23,13 @@ * */ =20 -#define VIRSH_COMMON_OPT_INTERFACE \ +#define VIRSH_COMMON_OPT_INTERFACE(cflags) \ {.name =3D "interface", \ .type =3D VSH_OT_DATA, \ .flags =3D VSH_OFLAG_REQ, \ - .help =3D N_("interface name or MAC address") \ + .help =3D N_("interface name or MAC address"), \ + .completer =3D virshInterfaceNameCompleter, \ + .completer_flags =3D cflags, \ } =20 #include @@ -107,7 +109,7 @@ static const vshCmdInfo info_interface_edit[] =3D { }; =20 static const vshCmdOptDef opts_interface_edit[] =3D { - VIRSH_COMMON_OPT_INTERFACE, + VIRSH_COMMON_OPT_INTERFACE(0), {.name =3D NULL} }; =20 @@ -467,7 +469,7 @@ static const vshCmdInfo info_interface_dumpxml[] =3D { }; =20 static const vshCmdOptDef opts_interface_dumpxml[] =3D { - VIRSH_COMMON_OPT_INTERFACE, + VIRSH_COMMON_OPT_INTERFACE(0), {.name =3D "inactive", .type =3D VSH_OT_BOOL, .help =3D N_("show inactive defined XML") @@ -564,7 +566,7 @@ static const vshCmdInfo info_interface_undefine[] =3D { }; =20 static const vshCmdOptDef opts_interface_undefine[] =3D { - VIRSH_COMMON_OPT_INTERFACE, + VIRSH_COMMON_OPT_INTERFACE(0), {.name =3D NULL} }; =20 @@ -603,7 +605,7 @@ static const vshCmdInfo info_interface_start[] =3D { }; =20 static const vshCmdOptDef opts_interface_start[] =3D { - VIRSH_COMMON_OPT_INTERFACE, + VIRSH_COMMON_OPT_INTERFACE(VIR_CONNECT_LIST_INTERFACES_INACTIVE), {.name =3D NULL} }; =20 @@ -642,7 +644,7 @@ static const vshCmdInfo info_interface_destroy[] =3D { }; =20 static const vshCmdOptDef opts_interface_destroy[] =3D { - VIRSH_COMMON_OPT_INTERFACE, + VIRSH_COMMON_OPT_INTERFACE(VIR_CONNECT_LIST_INTERFACES_ACTIVE), {.name =3D NULL} }; =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list