From nobody Sun May 5 02:48:42 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 1554369928486255.8649049904053; Thu, 4 Apr 2019 02:25:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB523C049598; Thu, 4 Apr 2019 09:25:26 +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 6048010018FB; Thu, 4 Apr 2019 09:25:25 +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 B8E9C41F3D; Thu, 4 Apr 2019 09:25:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x349PKGi004395 for ; Thu, 4 Apr 2019 05:25:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id A4C931001DEE; Thu, 4 Apr 2019 09:25:20 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D43E10018FB for ; Thu, 4 Apr 2019 09:25:17 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 4 Apr 2019 11:25:12 +0200 Message-Id: <685a43166a7e4c0dd9b1304f4179512cc95f8d0a.1554369912.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh: Add virshDomainShutdownModeCompleter 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 04 Apr 2019 09:25:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This completer is used to offer shutdown/reboot modes. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- tools/virsh-completer.c | 56 +++++++++++++++++++++++++++++++++++++++++ tools/virsh-completer.h | 4 +++ tools/virsh-domain.c | 2 ++ 3 files changed, 62 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index aac4579d1f..918e409890 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -936,3 +936,59 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); return ret; } + + +char ** +virshDomainShutdownModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + const char *modes[] =3D {"acpi", "agent", "initctl", "signal", "paravi= rt"}; + size_t i; + char **ret =3D NULL; + size_t ntmp =3D 0; + VIR_AUTOSTRINGLIST tmp =3D NULL; + const char *modeConst =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; + VIR_AUTOSTRINGLIST modesSpecified =3D NULL; + + virCheckFlags(0, NULL); + + if (vshCommandOptStringQuiet(ctl, cmd, "mode", &modeConst) < 0) + return NULL; + + if (STREQ_NULLABLE(modeConst, " ")) + modeConst =3D NULL; + + if (modeConst) { + char *modeTmp =3D NULL; + + if (VIR_STRDUP(mode, modeConst) < 0) + return NULL; + + if ((modeTmp =3D strrchr(mode, ','))) + *modeTmp =3D '\0'; + else + VIR_FREE(mode); + } + + if (mode && !(modesSpecified =3D virStringSplit(mode, ",", 0))) + return NULL; + + if (VIR_ALLOC_N(tmp, ARRAY_CARDINALITY(modes) + 1) < 0) + return NULL; + + for (i =3D 0; i < ARRAY_CARDINALITY(modes); i++) { + if (virStringListHasString((const char **)modesSpecified, modes[i]= )) + continue; + + if ((mode && virAsprintf(&tmp[ntmp], "%s,%s", mode, modes[i]) < 0)= || + (!mode && VIR_STRDUP(tmp[ntmp], modes[i]) < 0)) + return NULL; + + ntmp++; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 2e2e1edafb..ed37a26cc9 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -110,4 +110,8 @@ char ** virshDomainDeviceAliasCompleter(vshControl *ctl, char ** virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshDomainShutdownModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); #endif /* LIBVIRT_VIRSH_COMPLETER_H */ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e8d5404acf..a8a0b2f20d 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5829,6 +5829,7 @@ static const vshCmdOptDef opts_shutdown[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "mode", .type =3D VSH_OT_STRING, + .completer =3D virshDomainShutdownModeCompleter, .help =3D N_("shutdown mode: acpi|agent|initctl|signal|paravirt") }, {.name =3D NULL} @@ -5913,6 +5914,7 @@ static const vshCmdOptDef opts_reboot[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "mode", .type =3D VSH_OT_STRING, + .completer =3D virshDomainShutdownModeCompleter, .help =3D N_("shutdown mode: acpi|agent|initctl|signal|paravirt") }, {.name =3D NULL} --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list