[libvirt] [PATCH v2 12/13] virsh: Add lifecycle type completion to set-lifecycle-action command

Lin Ma lma at suse.com
Tue Nov 10 09:51:03 UTC 2020


Signed-off-by: Lin Ma <lma at suse.com>
---
 tools/virsh-completer-domain.c | 20 ++++++++++++++++++++
 tools/virsh-completer-domain.h |  4 ++++
 tools/virsh-domain.c           |  1 +
 3 files changed, 25 insertions(+)

diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index b8b6c74f8b..b1b670ffc5 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -731,3 +731,23 @@ virshDomainSignalCompleter(vshControl *ctl G_GNUC_UNUSED,
 
     return g_steal_pointer(&tmp);
 }
+
+char **
+virshDomainLifecycleCompleter(vshControl *ctl G_GNUC_UNUSED,
+                              const vshCmd *cmd G_GNUC_UNUSED,
+                              unsigned int flags)
+{
+    size_t i = 0;
+    VIR_AUTOSTRINGLIST tmp = NULL;
+
+    virCheckFlags(0, NULL);
+
+    tmp = g_new0(char *, VIR_DOMAIN_LIFECYCLE_LAST + 1);
+
+    for (i = 0; i < VIR_DOMAIN_LIFECYCLE_LAST; i++) {
+        const char *name = virDomainLifecycleTypeToString(i);
+        tmp[i] = g_strdup(name);
+    }
+
+    return g_steal_pointer(&tmp);
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index cdec66f23e..70f6e30947 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -102,3 +102,7 @@ char ** virshDomainConsoleCompleter(vshControl *ctl,
 char ** virshDomainSignalCompleter(vshControl *ctl,
                                    const vshCmd *cmd,
                                    unsigned int flags);
+
+char ** virshDomainLifecycleCompleter(vshControl *ctl,
+                                      const vshCmd *cmd,
+                                      unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1406bb4583..be91bd48fc 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5717,6 +5717,7 @@ static const vshCmdOptDef opts_setLifecycleAction[] = {
     {.name = "type",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshDomainLifecycleCompleter,
      .help = N_("lifecycle type to modify")
     },
     {.name = "action",
-- 
2.26.0





More information about the libvir-list mailing list