From nobody Thu May 15 03:12:31 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 1515768072424702.8028963669996; Fri, 12 Jan 2018 06:41:12 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86A1F8E223; Fri, 12 Jan 2018 14:41:05 +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 92E2B17974; Fri, 12 Jan 2018 14:41:01 +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 A72D7410B7; Fri, 12 Jan 2018 14:40:56 +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 w0CEcB9w025698 for ; Fri, 12 Jan 2018 09:38:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id C77A7176B0; Fri, 12 Jan 2018 14:38:11 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D86065604 for ; Fri, 12 Jan 2018 14:38:10 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 12 Jan 2018 15:37:42 +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 8/8] virsh: Introduce virshSnapshotNameCompleter 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 12 Jan 2018 14:41:11 +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-snapshot.c | 21 +++++++++++++------- 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 7332fa97a..9db7c59d2 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -484,3 +484,54 @@ virshSecretUUIDCompleter(vshControl *ctl, VIR_FREE(ret); return NULL; } + + +char ** +virshSnapshotNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virDomainPtr dom =3D NULL; + virDomainSnapshotPtr *snapshots =3D NULL; + int nsnapshots =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + if ((nsnapshots =3D virDomainListAllSnapshots(dom, &snapshots, flags))= < 0) + goto error; + + if (VIR_ALLOC_N(ret, nsnapshots + 1) < 0) + goto error; + + for (i =3D 0; i < nsnapshots; i++) { + const char *name =3D virDomainSnapshotGetName(snapshots[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virshDomainSnapshotFree(snapshots[i]); + } + VIR_FREE(snapshots); + virshDomainFree(dom); + + return ret; + + error: + for (; i < nsnapshots; i++) + virshDomainSnapshotFree(snapshots[i]); + VIR_FREE(snapshots); + for (i =3D 0; i < nsnapshots; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + virshDomainFree(dom); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 0e518873c..fa443d3ad 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -66,4 +66,8 @@ char ** virshSecretUUIDCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshSnapshotNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index c44a36f98..e4908eea7 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -511,7 +511,8 @@ static const vshCmdOptDef opts_snapshot_edit[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, - .help =3D N_("snapshot name") + .help =3D N_("snapshot name"), + .completer =3D virshSnapshotNameCompleter, }, VIRSH_COMMON_OPT_CURRENT(N_("also set edited snapshot as current")), {.name =3D "rename", @@ -631,7 +632,8 @@ static const vshCmdOptDef opts_snapshot_current[] =3D { }, {.name =3D "snapshotname", .type =3D VSH_OT_STRING, - .help =3D N_("name of existing snapshot to make current") + .help =3D N_("name of existing snapshot to make current"), + .completer =3D virshSnapshotNameCompleter, }, {.name =3D NULL} }; @@ -854,7 +856,8 @@ static const vshCmdOptDef opts_snapshot_info[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, - .help =3D N_("snapshot name") + .help =3D N_("snapshot name"), + .completer =3D virshSnapshotNameCompleter, }, VIRSH_COMMON_OPT_CURRENT(N_("info on current snapshot")), {.name =3D NULL} @@ -1661,7 +1664,8 @@ static const vshCmdOptDef opts_snapshot_dumpxml[] =3D= { {.name =3D "snapshotname", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, - .help =3D N_("snapshot name") + .help =3D N_("snapshot name"), + .completer =3D virshSnapshotNameCompleter, }, {.name =3D "security-info", .type =3D VSH_OT_BOOL, @@ -1723,7 +1727,8 @@ static const vshCmdOptDef opts_snapshot_parent[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, - .help =3D N_("find parent of snapshot name") + .help =3D N_("find parent of snapshot name"), + .completer =3D virshSnapshotNameCompleter, }, VIRSH_COMMON_OPT_CURRENT(N_("find parent of current snapshot")), {.name =3D NULL} @@ -1782,7 +1787,8 @@ static const vshCmdOptDef opts_snapshot_revert[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, - .help =3D N_("snapshot name") + .help =3D N_("snapshot name"), + .completer =3D virshSnapshotNameCompleter, }, VIRSH_COMMON_OPT_CURRENT(N_("revert to current snapshot")), {.name =3D "running", @@ -1866,7 +1872,8 @@ static const vshCmdOptDef opts_snapshot_delete[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, - .help =3D N_("snapshot name") + .help =3D N_("snapshot name"), + .completer =3D virshSnapshotNameCompleter, }, VIRSH_COMMON_OPT_CURRENT(N_("delete current snapshot")), {.name =3D "children", --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list