From nobody Mon May 13 14:49:37 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530009842995592.4281930591583; Tue, 26 Jun 2018 03:44:02 -0700 (PDT) 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 AB7DC30C1118; Tue, 26 Jun 2018 10:44:01 +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 1D4861814C; Tue, 26 Jun 2018 10:44: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 048D618037ED; Tue, 26 Jun 2018 10:44:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5QAhwNN015061 for ; Tue, 26 Jun 2018 06:43:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 440572166BA0; Tue, 26 Jun 2018 10:43:58 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBEB12166B5D for ; Tue, 26 Jun 2018 10:43:57 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 26 Jun 2018 12:43:51 +0200 Message-Id: <1324c1d6aea15f29e1f85188673649474730bd4f.1530009831.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh: Provide completer for detach-device-alias 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.46]); Tue, 26 Jun 2018 10:44:02 +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 | 48 +++++++++++++++++++++++++++++++++++++++++++++= +++ tools/virsh-completer.h | 4 ++++ tools/virsh-domain.c | 1 + 3 files changed, 53 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index d3effe59ea..ae579a5bdb 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -811,3 +811,51 @@ virshCellnoCompleter(vshControl *ctl, VIR_FREE(ret); goto cleanup; } + + +char ** +virshDomainDeviceAliasCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + xmlDocPtr xmldoc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + int naliases; + xmlNodePtr *aliases =3D NULL; + size_t i; + unsigned int domainXMLFlags =3D 0; + char **ret =3D NULL; + char **tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (vshCommandOptBool(cmd, "config")) + domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; + + if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) + goto cleanup; + + naliases =3D virXPathNodeSet("./devices//alias/@name", ctxt, &aliases); + if (naliases < 0) + goto cleanup; + + if (VIR_ALLOC_N(tmp, naliases + 1) < 0) + goto cleanup; + + for (i =3D 0; i < naliases; i++) { + if (!(tmp[i] =3D virXMLNodeContentString(aliases[i]))) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + cleanup: + VIR_FREE(aliases); + xmlFreeDoc(xmldoc); + xmlXPathFreeContext(ctxt); + virStringListFree(tmp); + return ret; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index ee7eec68c5..50dc068d73 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -94,6 +94,10 @@ char ** virshNodedevEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshDomainDeviceAliasCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + char ** virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 6aa79f11b9..e9b88f0013 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11684,6 +11684,7 @@ static const vshCmdOptDef opts_detach_device_alias[= ] =3D { {.name =3D "alias", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshDomainDeviceAliasCompleter, .help =3D N_("device alias") }, VIRSH_COMMON_OPT_DOMAIN_CONFIG, --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list