]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Use VIR_ENUM_* for --target argument in cmdNodeSuspend
authorLin Ma <lma@suse.com>
Tue, 15 Jun 2021 00:38:22 +0000 (08:38 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 15 Jun 2021 08:27:53 +0000 (10:27 +0200)
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-host.c
tools/virsh-host.h

index 1eca0bc231ec7758479ce425a0d3c1cb00122410..9d6d2b3645907bec95ab755e3c2a8a43caca63b6 100644 (file)
@@ -950,6 +950,13 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
 /*
  * "nodesuspend" command
  */
+
+VIR_ENUM_IMPL(virNodeSuspendTarget,
+              VIR_NODE_SUSPEND_TARGET_LAST,
+              "mem",
+              "disk",
+              "hybrid");
+
 static const vshCmdInfo info_nodesuspend[] = {
     {.name = "help",
      .data = N_("suspend the host node for a given time duration")
@@ -980,7 +987,7 @@ static bool
 cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
 {
     const char *target = NULL;
-    unsigned int suspendTarget;
+    int suspendTarget;
     long long duration;
     virshControl *priv = ctl->privData;
 
@@ -990,13 +997,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptLongLong(ctl, cmd, "duration", &duration) < 0)
         return false;
 
-    if (STREQ(target, "mem")) {
-        suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM;
-    } else if (STREQ(target, "disk")) {
-        suspendTarget = VIR_NODE_SUSPEND_TARGET_DISK;
-    } else if (STREQ(target, "hybrid")) {
-        suspendTarget = VIR_NODE_SUSPEND_TARGET_HYBRID;
-    } else {
+    if ((suspendTarget = virNodeSuspendTargetTypeFromString(target)) < 0) {
         vshError(ctl, "%s", _("Invalid target"));
         return false;
     }
index 92328c7deb35ff34d8b7b4328e0b8d398aa54b14..840f0b4538176ecfc014da6c6e564112b998c4eb 100644 (file)
@@ -21,5 +21,8 @@
 #pragma once
 
 #include "vsh.h"
+#include "virenum.h"
 
 extern const vshCmdDef hostAndHypervisorCmds[];
+
+VIR_ENUM_DECL(virNodeSuspendTarget);