From nobody Thu May 15 13:30:19 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 1508152051829513.9688052559803; Mon, 16 Oct 2017 04:07:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2D0181E00; Mon, 16 Oct 2017 11:07: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 8B5356292F; Mon, 16 Oct 2017 11:07:30 +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 53C5C5EC67; Mon, 16 Oct 2017 11:07:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9GB6eaV008750 for ; Mon, 16 Oct 2017 07:06:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id E7D8C5D965; Mon, 16 Oct 2017 11:06:40 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FFC25D964 for ; Mon, 16 Oct 2017 11:06:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B2D0181E00 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 16 Oct 2017 13:06:24 +0200 Message-Id: <7e212467e81b71d5f969edbd7799e03d9e72d157.1508151956.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/14] virsh: introduce set-lifecycle-action command 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 16 Oct 2017 11:07:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- tools/virsh-domain.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh.pod | 7 ++++ 2 files changed, 109 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index a50713d6e4..bdafdf6f5d 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5517,6 +5517,102 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) } =20 /* + * "set-lifecycle-action" command + */ +static const vshCmdInfo info_setLifecycleAction[] =3D { + {.name =3D "help", + .data =3D N_("change lifecycle actions") + }, + {.name =3D "desc", + .data =3D N_("Change lifecycle actions for the guest domain.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_setLifecycleAction[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL, + {.name =3D "type", + .type =3D VSH_OT_STRING, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("lifecycle type to modify") + }, + {.name =3D "action", + .type =3D VSH_OT_STRING, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("lifecycle action to set") + }, + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; + +VIR_ENUM_IMPL(virDomainLifecycle, VIR_DOMAIN_LIFECYCLE_LAST, + "poweroff", + "reboot", + "crash") + +VIR_ENUM_IMPL(virDomainLifecycleAction, VIR_DOMAIN_LIFECYCLE_ACTION_LAST, + "destroy", + "restart", + "rename-restart", + "preserve", + "coredump-destroy", + "coredump-restart") + +static bool +cmdSetLifecycleAction(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom; + bool ret =3D true; + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + bool current =3D vshCommandOptBool(cmd, "current"); + const char *typeStr; + const char *actionStr; + unsigned int type; + unsigned int action; + unsigned int flags =3D 0; + int tmpVal; + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (vshCommandOptStringReq(ctl, cmd, "type", &typeStr) < 0 || + vshCommandOptStringReq(ctl, cmd, "action", &actionStr) < 0) { + return false; + } + + if ((tmpVal =3D virDomainLifecycleTypeFromString(typeStr)) < 0) { + return false; + vshError(ctl, _("Invalid lifecycle type '%s'."), typeStr); + } + type =3D tmpVal; + + if ((tmpVal =3D virDomainLifecycleActionTypeFromString(actionStr)) < 0= ) { + vshError(ctl, _("Invalid lifecycle action '%s'."), actionStr); + return false; + } + action =3D tmpVal; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virDomainSetLifecycleAction(dom, type, action, flags) < 0) { + vshError(ctl, "%s", _("Unable to change lifecycle action.")); + ret =3D false; + } + + virshDomainFree(dom); + return ret; +} + +/* * "set-user-password" command */ static const vshCmdInfo info_set_user_password[] =3D { @@ -14249,6 +14345,12 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_screenshot, .flags =3D 0 }, + {.name =3D "set-lifecycle-action", + .handler =3D cmdSetLifecycleAction, + .opts =3D opts_setLifecycleAction, + .info =3D info_setLifecycleAction, + .flags =3D 0 + }, {.name =3D "set-user-password", .handler =3D cmdSetUserPassword, .opts =3D opts_set_user_password, diff --git a/tools/virsh.pod b/tools/virsh.pod index 024d027699..39cb67792a 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2327,6 +2327,13 @@ the value from the host, use the B co= mmand. In order to view the current memory in use and the maximum value allowed to set memory, use the B command. =20 +=3Ditem B I I I +[[I<--config>] [I<--live>] | [I<--current>]] + +Set the lifecycle action for specified lifecycle type. For the list of +lifecycle types and actions and possible combinations see the documentatio= n at +L. + =3Ditem B I I I [I<--encrypted>] =20 Set the password for the I account in the guest domain. --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list