Re: [libvirt] [PATCH 11/14] virsh: introduce set-lifecycle-action command

2017-10-19 Thread Pavel Hrdina
On Wed, Oct 18, 2017 at 04:39:02PM -0400, John Ferlan wrote:
> 
> 
> On 10/16/2017 07:06 AM, Pavel Hrdina wrote:
> > 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)
> >  }
> >  
> >  /*
> > + * "set-lifecycle-action" command
> > + */
> > +static const vshCmdInfo info_setLifecycleAction[] = {
> > +{.name = "help",
> > + .data = N_("change lifecycle actions")
> > +},
> > +{.name = "desc",
> > + .data = N_("Change lifecycle actions for the guest domain.")
> > +},
> > +{.name = NULL}
> > +};
> > +
> > +static const vshCmdOptDef opts_setLifecycleAction[] = {
> > +VIRSH_COMMON_OPT_DOMAIN_FULL,
> > +{.name = "type",
> > + .type = VSH_OT_STRING,
> > + .flags = VSH_OFLAG_REQ,
> > + .help = N_("lifecycle type to modify")
> > +},
> > +{.name = "action",
> > + .type = VSH_OT_STRING,
> > + .flags = VSH_OFLAG_REQ,
> > + .help = N_("lifecycle action to set")
> > +},
> > +VIRSH_COMMON_OPT_DOMAIN_CONFIG,
> > +VIRSH_COMMON_OPT_DOMAIN_LIVE,
> > +VIRSH_COMMON_OPT_DOMAIN_CURRENT,
> > +{.name = 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 = true;
> > +bool config = vshCommandOptBool(cmd, "config");
> > +bool live = vshCommandOptBool(cmd, "live");
> > +bool current = vshCommandOptBool(cmd, "current");
> > +const char *typeStr;
> > +const char *actionStr;
> > +unsigned int type;
> > +unsigned int action;
> > +unsigned int flags = 0;
> > +int tmpVal;
> > +
> > +VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
> > +VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
> > +
> > +if (config)
> > +flags |= VIR_DOMAIN_AFFECT_CONFIG;
> > +if (live)
> > +flags |= VIR_DOMAIN_AFFECT_LIVE;
> > +
> > +if (vshCommandOptStringReq(ctl, cmd, "type", ) < 0 ||
> > +vshCommandOptStringReq(ctl, cmd, "action", ) < 0) {
> > +return false;
> > +}
> > +
> > +if ((tmpVal = virDomainLifecycleTypeFromString(typeStr)) < 0) {
> > +return false;
> > +vshError(ctl, _("Invalid lifecycle type '%s'."), typeStr);
> 
> unreachable ;-) as the order is reversed (Coverity didn't even notice,
> go figure!

Nice catch :)

> > +}
> > +type = tmpVal;
> > +
> > +if ((tmpVal = virDomainLifecycleActionTypeFromString(actionStr)) < 0) {
> > +vshError(ctl, _("Invalid lifecycle action '%s'."), actionStr);
> > +return false;
> > +}
> > +action = tmpVal;
> > +
> > +if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
> > +return false;
> > +
> > +if (virDomainSetLifecycleAction(dom, type, action, flags) < 0) {
> > +vshError(ctl, "%s", _("Unable to change lifecycle action."));
> > +ret = false;
> > +}
> > +
> > +virshDomainFree(dom);
> > +return ret;
> > +}
> > +
> > +/*
> >   * "set-user-password" command
> >   */
> >  static const vshCmdInfo info_set_user_password[] = {
> > @@ -14249,6 +14345,12 @@ const vshCmdDef domManagementCmds[] = {
> >   .info = info_screenshot,
> >   .flags = 0
> >  },
> > +{.name = "set-lifecycle-action",
> > + .handler = cmdSetLifecycleAction,
> > + .opts = opts_setLifecycleAction,
> > + .info = info_setLifecycleAction,
> > + .flags = 0
> > +},
> >  {.name = "set-user-password",
> >   .handler = cmdSetUserPassword,
> >   .opts = 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 
> > command. In order to view
> >  the current memory in use and the maximum value allowed to set memory, use
> >  the B command.
> >  
> > +=item B I I I
> > +[[I<--config>] [I<--live>] | [I<--current>]]
> > +
> > +Set the lifecycle action for specified lifecycle type. For the list of
> 
> s/action/I
> s/type/I

Fixed

> consider "lifecycle event type" - IDC if you do or not, just a thought
 
I was thinking about the "event" for a long 

Re: [libvirt] [PATCH 11/14] virsh: introduce set-lifecycle-action command

2017-10-18 Thread John Ferlan


On 10/16/2017 07:06 AM, Pavel Hrdina wrote:
> 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)
>  }
>  
>  /*
> + * "set-lifecycle-action" command
> + */
> +static const vshCmdInfo info_setLifecycleAction[] = {
> +{.name = "help",
> + .data = N_("change lifecycle actions")
> +},
> +{.name = "desc",
> + .data = N_("Change lifecycle actions for the guest domain.")
> +},
> +{.name = NULL}
> +};
> +
> +static const vshCmdOptDef opts_setLifecycleAction[] = {
> +VIRSH_COMMON_OPT_DOMAIN_FULL,
> +{.name = "type",
> + .type = VSH_OT_STRING,
> + .flags = VSH_OFLAG_REQ,
> + .help = N_("lifecycle type to modify")
> +},
> +{.name = "action",
> + .type = VSH_OT_STRING,
> + .flags = VSH_OFLAG_REQ,
> + .help = N_("lifecycle action to set")
> +},
> +VIRSH_COMMON_OPT_DOMAIN_CONFIG,
> +VIRSH_COMMON_OPT_DOMAIN_LIVE,
> +VIRSH_COMMON_OPT_DOMAIN_CURRENT,
> +{.name = 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 = true;
> +bool config = vshCommandOptBool(cmd, "config");
> +bool live = vshCommandOptBool(cmd, "live");
> +bool current = vshCommandOptBool(cmd, "current");
> +const char *typeStr;
> +const char *actionStr;
> +unsigned int type;
> +unsigned int action;
> +unsigned int flags = 0;
> +int tmpVal;
> +
> +VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
> +VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
> +
> +if (config)
> +flags |= VIR_DOMAIN_AFFECT_CONFIG;
> +if (live)
> +flags |= VIR_DOMAIN_AFFECT_LIVE;
> +
> +if (vshCommandOptStringReq(ctl, cmd, "type", ) < 0 ||
> +vshCommandOptStringReq(ctl, cmd, "action", ) < 0) {
> +return false;
> +}
> +
> +if ((tmpVal = virDomainLifecycleTypeFromString(typeStr)) < 0) {
> +return false;
> +vshError(ctl, _("Invalid lifecycle type '%s'."), typeStr);

unreachable ;-) as the order is reversed (Coverity didn't even notice,
go figure!

> +}
> +type = tmpVal;
> +
> +if ((tmpVal = virDomainLifecycleActionTypeFromString(actionStr)) < 0) {
> +vshError(ctl, _("Invalid lifecycle action '%s'."), actionStr);
> +return false;
> +}
> +action = tmpVal;
> +
> +if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
> +return false;
> +
> +if (virDomainSetLifecycleAction(dom, type, action, flags) < 0) {
> +vshError(ctl, "%s", _("Unable to change lifecycle action."));
> +ret = false;
> +}
> +
> +virshDomainFree(dom);
> +return ret;
> +}
> +
> +/*
>   * "set-user-password" command
>   */
>  static const vshCmdInfo info_set_user_password[] = {
> @@ -14249,6 +14345,12 @@ const vshCmdDef domManagementCmds[] = {
>   .info = info_screenshot,
>   .flags = 0
>  },
> +{.name = "set-lifecycle-action",
> + .handler = cmdSetLifecycleAction,
> + .opts = opts_setLifecycleAction,
> + .info = info_setLifecycleAction,
> + .flags = 0
> +},
>  {.name = "set-user-password",
>   .handler = cmdSetUserPassword,
>   .opts = 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 
> command. In order to view
>  the current memory in use and the maximum value allowed to set memory, use
>  the B command.
>  
> +=item B I I I
> +[[I<--config>] [I<--live>] | [I<--current>]]
> +
> +Set the lifecycle action for specified lifecycle type. For the list of

s/action/I
s/type/I

consider "lifecycle event type" - IDC if you do or not, just a thought


> +lifecycle types and actions and possible combinations see the documentation 
> at
> +L.

Probably should add the obligatory what --config, --live, and --current do.


John
> +
>  =item B I I I [I<--encrypted>]
>  
>  Set the password for the I account in the guest domain.
> 

--
libvir-list mailing list
libvir-list@redhat.com

[libvirt] [PATCH 11/14] virsh: introduce set-lifecycle-action command

2017-10-16 Thread Pavel Hrdina
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)
 }
 
 /*
+ * "set-lifecycle-action" command
+ */
+static const vshCmdInfo info_setLifecycleAction[] = {
+{.name = "help",
+ .data = N_("change lifecycle actions")
+},
+{.name = "desc",
+ .data = N_("Change lifecycle actions for the guest domain.")
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_setLifecycleAction[] = {
+VIRSH_COMMON_OPT_DOMAIN_FULL,
+{.name = "type",
+ .type = VSH_OT_STRING,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("lifecycle type to modify")
+},
+{.name = "action",
+ .type = VSH_OT_STRING,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("lifecycle action to set")
+},
+VIRSH_COMMON_OPT_DOMAIN_CONFIG,
+VIRSH_COMMON_OPT_DOMAIN_LIVE,
+VIRSH_COMMON_OPT_DOMAIN_CURRENT,
+{.name = 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 = true;
+bool config = vshCommandOptBool(cmd, "config");
+bool live = vshCommandOptBool(cmd, "live");
+bool current = vshCommandOptBool(cmd, "current");
+const char *typeStr;
+const char *actionStr;
+unsigned int type;
+unsigned int action;
+unsigned int flags = 0;
+int tmpVal;
+
+VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
+VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
+
+if (config)
+flags |= VIR_DOMAIN_AFFECT_CONFIG;
+if (live)
+flags |= VIR_DOMAIN_AFFECT_LIVE;
+
+if (vshCommandOptStringReq(ctl, cmd, "type", ) < 0 ||
+vshCommandOptStringReq(ctl, cmd, "action", ) < 0) {
+return false;
+}
+
+if ((tmpVal = virDomainLifecycleTypeFromString(typeStr)) < 0) {
+return false;
+vshError(ctl, _("Invalid lifecycle type '%s'."), typeStr);
+}
+type = tmpVal;
+
+if ((tmpVal = virDomainLifecycleActionTypeFromString(actionStr)) < 0) {
+vshError(ctl, _("Invalid lifecycle action '%s'."), actionStr);
+return false;
+}
+action = tmpVal;
+
+if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+return false;
+
+if (virDomainSetLifecycleAction(dom, type, action, flags) < 0) {
+vshError(ctl, "%s", _("Unable to change lifecycle action."));
+ret = false;
+}
+
+virshDomainFree(dom);
+return ret;
+}
+
+/*
  * "set-user-password" command
  */
 static const vshCmdInfo info_set_user_password[] = {
@@ -14249,6 +14345,12 @@ const vshCmdDef domManagementCmds[] = {
  .info = info_screenshot,
  .flags = 0
 },
+{.name = "set-lifecycle-action",
+ .handler = cmdSetLifecycleAction,
+ .opts = opts_setLifecycleAction,
+ .info = info_setLifecycleAction,
+ .flags = 0
+},
 {.name = "set-user-password",
  .handler = cmdSetUserPassword,
  .opts = 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 
command. In order to view
 the current memory in use and the maximum value allowed to set memory, use
 the B command.
 
+=item 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 documentation at
+L.
+
 =item B I I I [I<--encrypted>]
 
 Set the password for the I account in the guest domain.
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list