From nobody Thu May 15 03:49: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 1515768047121469.4513505965642; Fri, 12 Jan 2018 06:40:47 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 01EA08047E; Fri, 12 Jan 2018 14:40:30 +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 C1E43179E9; Fri, 12 Jan 2018 14:40:27 +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 0DA57410B3; Fri, 12 Jan 2018 14:40:22 +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 w0CEc3QM025644 for ; Fri, 12 Jan 2018 09:38:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 029A56560E; Fri, 12 Jan 2018 14:38:03 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BECA6562B for ; Fri, 12 Jan 2018 14:37:59 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 12 Jan 2018 15:37:38 +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 4/8] virsh: Introduce virshNetworkNameCompleter 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 12 Jan 2018 14:40:46 +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 | 51 +++++++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh-completer.h | 4 ++++ tools/virsh-network.c | 24 ++++++++++++----------- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index f5b1e4261..2c0d4f640 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -297,3 +297,54 @@ virshInterfaceNameCompleter(vshControl *ctl, VIR_FREE(ret); return NULL; } + + +char ** +virshNetworkNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNetworkPtr *nets =3D NULL; + int nnets =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(VIR_CONNECT_LIST_NETWORKS_INACTIVE | + VIR_CONNECT_LIST_NETWORKS_ACTIVE | + VIR_CONNECT_LIST_NETWORKS_PERSISTENT | + VIR_CONNECT_LIST_NETWORKS_TRANSIENT | + VIR_CONNECT_LIST_NETWORKS_AUTOSTART | + VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART, + NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((nnets =3D virConnectListAllNetworks(priv->conn, &nets, flags)) < = 0) + return NULL; + + if (VIR_ALLOC_N(ret, nnets + 1) < 0) + goto error; + + for (i =3D 0; i < nnets; i++) { + const char *name =3D virNetworkGetName(nets[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virNetworkFree(nets[i]); + } + VIR_FREE(nets); + + return ret; + + error: + for (; i < nnets; i++) + virNetworkFree(nets[i]); + VIR_FREE(nets); + for (i =3D 0; i < nnets; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 2323aaba3..20ba4cb55 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -50,4 +50,8 @@ char ** virshInterfaceNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshNetworkNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-network.c b/tools/virsh-network.c index cd55e384f..3b472ea67 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -34,11 +34,13 @@ #include "virtime.h" #include "conf/network_conf.h" =20 -#define VIRSH_COMMON_OPT_NETWORK \ +#define VIRSH_COMMON_OPT_NETWORK(cflags) \ {.name =3D "network", \ .type =3D VSH_OT_DATA, \ .flags =3D VSH_OFLAG_REQ, \ - .help =3D N_("network name or uuid") \ + .help =3D N_("network name or uuid"), \ + .completer =3D virshNetworkNameCompleter, \ + .completer_flags =3D cflags, \ } =20 virNetworkPtr @@ -93,7 +95,7 @@ static const vshCmdInfo info_network_autostart[] =3D { }; =20 static const vshCmdOptDef opts_network_autostart[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(0), {.name =3D "disable", .type =3D VSH_OT_BOOL, .help =3D N_("disable autostarting") @@ -240,7 +242,7 @@ static const vshCmdInfo info_network_destroy[] =3D { }; =20 static const vshCmdOptDef opts_network_destroy[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(VIR_CONNECT_LIST_NETWORKS_ACTIVE), {.name =3D NULL} }; =20 @@ -279,7 +281,7 @@ static const vshCmdInfo info_network_dumpxml[] =3D { }; =20 static const vshCmdOptDef opts_network_dumpxml[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(0), {.name =3D "inactive", .type =3D VSH_OT_BOOL, .help =3D N_("show inactive defined XML") @@ -330,7 +332,7 @@ static const vshCmdInfo info_network_info[] =3D { }; =20 static const vshCmdOptDef opts_network_info[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(0), {.name =3D NULL} }; =20 @@ -779,7 +781,7 @@ static const vshCmdInfo info_network_start[] =3D { }; =20 static const vshCmdOptDef opts_network_start[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(VIR_CONNECT_LIST_NETWORKS_INACTIVE), {.name =3D NULL} }; =20 @@ -817,7 +819,7 @@ static const vshCmdInfo info_network_undefine[] =3D { }; =20 static const vshCmdOptDef opts_network_undefine[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(0), {.name =3D NULL} }; =20 @@ -856,7 +858,7 @@ static const vshCmdInfo info_network_update[] =3D { }; =20 static const vshCmdOptDef opts_network_update[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(0), {.name =3D "command", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -1057,7 +1059,7 @@ static const vshCmdInfo info_network_edit[] =3D { }; =20 static const vshCmdOptDef opts_network_edit[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(0), {.name =3D NULL} }; =20 @@ -1304,7 +1306,7 @@ static const vshCmdInfo info_network_dhcp_leases[] = =3D { }; =20 static const vshCmdOptDef opts_network_dhcp_leases[] =3D { - VIRSH_COMMON_OPT_NETWORK, + VIRSH_COMMON_OPT_NETWORK(0), {.name =3D "mac", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_NONE, --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list