]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Introduce virshStoragePoolNameCompleter
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 12 Jan 2018 13:01:33 +0000 (14:01 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 24 Jan 2018 12:49:56 +0000 (13:49 +0100)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
tools/virsh-completer.c
tools/virsh-completer.h
tools/virsh-pool.c
tools/virsh-volume.c
tools/virsh.h

index 48dd9fbc2bc549d9699c27fc0c5c57eeb5ce8614..947c326fcc80580591eabc0dabb8592448816fe8 100644 (file)
@@ -147,3 +147,51 @@ virshDomainInterfaceCompleter(vshControl *ctl,
     virStringListFree(ret);
     return NULL;
 }
+
+
+char **
+virshStoragePoolNameCompleter(vshControl *ctl,
+                              const vshCmd *cmd ATTRIBUTE_UNUSED,
+                              unsigned int flags)
+{
+    virshControlPtr priv = ctl->privData;
+    virStoragePoolPtr *pools = NULL;
+    int npools = 0;
+    size_t i = 0;
+    char **ret = NULL;
+
+    virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE |
+                  VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
+                  VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT,
+                  NULL);
+
+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+        return NULL;
+
+    if ((npools = virConnectListAllStoragePools(priv->conn, &pools, flags)) < 0)
+        return NULL;
+
+    if (VIR_ALLOC_N(ret, npools + 1) < 0)
+        goto error;
+
+    for (i = 0; i < npools; i++) {
+        const char *name = virStoragePoolGetName(pools[i]);
+
+        if (VIR_STRDUP(ret[i], name) < 0)
+            goto error;
+
+        virStoragePoolFree(pools[i]);
+    }
+    VIR_FREE(pools);
+
+    return ret;
+
+ error:
+    for (; i < npools; i++)
+        virStoragePoolFree(pools[i]);
+    VIR_FREE(pools);
+    for (i = 0; i < npools; i++)
+        VIR_FREE(ret[i]);
+    VIR_FREE(ret);
+    return NULL;
+}
index 1a2dd685fb05a27b1de1d4e836b5e6a6201ed56c..249e793b9f5e76f7ed519f09c89950fc77374a85 100644 (file)
@@ -38,4 +38,8 @@ char ** virshDomainInterfaceCompleter(vshControl *ctl,
                                       const vshCmd *cmd,
                                       unsigned int flags);
 
+char ** virshStoragePoolNameCompleter(vshControl *ctl,
+                                      const vshCmd *cmd,
+                                      unsigned int flags);
+
 #endif
index 094874b643e0fb12022c5c76780f69ab77134264..56b6cfc73dea26e7147c41f0898520dc952e8c1e 100644 (file)
@@ -34,8 +34,8 @@
 #include "virstring.h"
 #include "virtime.h"
 
-#define VIRSH_COMMON_OPT_POOL_FULL \
-    VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"))
+#define VIRSH_COMMON_OPT_POOL_FULL(cflags) \
+    VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), cflags)
 
 #define VIRSH_COMMON_OPT_POOL_BUILD \
     {.name = "build", \
@@ -182,7 +182,7 @@ static const vshCmdInfo info_pool_autostart[] = {
 };
 
 static const vshCmdOptDef opts_pool_autostart[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT),
 
     {.name = "disable",
      .type = VSH_OT_BOOL,
@@ -575,7 +575,7 @@ static const vshCmdInfo info_pool_build[] = {
 };
 
 static const vshCmdOptDef opts_pool_build[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(0),
     VIRSH_COMMON_OPT_POOL_NO_OVERWRITE,
     VIRSH_COMMON_OPT_POOL_OVERWRITE,
 
@@ -625,7 +625,7 @@ static const vshCmdInfo info_pool_destroy[] = {
 };
 
 static const vshCmdOptDef opts_pool_destroy[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE),
 
     {.name = NULL}
 };
@@ -665,7 +665,7 @@ static const vshCmdInfo info_pool_delete[] = {
 };
 
 static const vshCmdOptDef opts_pool_delete[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE),
 
     {.name = NULL}
 };
@@ -705,7 +705,7 @@ static const vshCmdInfo info_pool_refresh[] = {
 };
 
 static const vshCmdOptDef opts_pool_refresh[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(0),
 
     {.name = NULL}
 };
@@ -745,7 +745,7 @@ static const vshCmdInfo info_pool_dumpxml[] = {
 };
 
 static const vshCmdOptDef opts_pool_dumpxml[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(0),
 
     {.name = "inactive",
      .type = VSH_OT_BOOL,
@@ -1636,7 +1636,7 @@ static const vshCmdInfo info_pool_info[] = {
 };
 
 static const vshCmdOptDef opts_pool_info[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(0),
 
     {.name = "bytes",
      .type = VSH_OT_BOOL,
@@ -1726,7 +1726,7 @@ static const vshCmdInfo info_pool_name[] = {
 };
 
 static const vshCmdOptDef opts_pool_name[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(0),
 
     {.name = NULL}
 };
@@ -1758,7 +1758,7 @@ static const vshCmdInfo info_pool_start[] = {
 };
 
 static const vshCmdOptDef opts_pool_start[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE),
     VIRSH_COMMON_OPT_POOL_BUILD,
     VIRSH_COMMON_OPT_POOL_NO_OVERWRITE,
     VIRSH_COMMON_OPT_POOL_OVERWRITE,
@@ -1819,7 +1819,7 @@ static const vshCmdInfo info_pool_undefine[] = {
 };
 
 static const vshCmdOptDef opts_pool_undefine[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT),
 
     {.name = NULL}
 };
@@ -1859,7 +1859,7 @@ static const vshCmdInfo info_pool_uuid[] = {
 };
 
 static const vshCmdOptDef opts_pool_uuid[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(0),
 
     {.name = NULL}
 };
@@ -1896,7 +1896,7 @@ static const vshCmdInfo info_pool_edit[] = {
 };
 
 static const vshCmdOptDef opts_pool_edit[] = {
-    VIRSH_COMMON_OPT_POOL_FULL,
+    VIRSH_COMMON_OPT_POOL_FULL(0),
 
     {.name = NULL}
 };
index 8265a39795b5c93bda6ab9124eac3527052bafe3..bfbb7c7d7a3b789fd1709f0d79e78fddd99f8d23 100644 (file)
 #include "virstring.h"
 
 #define VIRSH_COMMON_OPT_POOL_FULL \
-    VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"))
+    VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), \
+                          VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)
 
 #define VIRSH_COMMON_OPT_POOL_NAME \
-    VIRSH_COMMON_OPT_POOL(N_("pool name"))
+    VIRSH_COMMON_OPT_POOL(N_("pool name"), \
+                          VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)
 
 #define VIRSH_COMMON_OPT_POOL_OPTIONAL \
     {.name = "pool", \
      .type = VSH_OT_STRING, \
-     .help = N_("pool name or uuid") \
+     .help = N_("pool name or uuid"), \
+     .completer = virshStoragePoolNameCompleter, \
+     .completer_flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE, \
     }
 
 #define VIRSH_COMMON_OPT_VOLUME_VOL \
index 528e04558f2a85e5e959421f05eeeded94d6321f..f2213ebb574812f353c722c168226c339257dfde 100644 (file)
 /*
  * Common command options
  */
-# define VIRSH_COMMON_OPT_POOL(_helpstr) \
+# define VIRSH_COMMON_OPT_POOL(_helpstr, cflags) \
     {.name = "pool", \
      .type = VSH_OT_DATA, \
      .flags = VSH_OFLAG_REQ, \
-     .help = _helpstr \
+     .help = _helpstr, \
+     .completer = virshStoragePoolNameCompleter, \
+     .completer_flags = cflags, \
     }
 
 # define VIRSH_COMMON_OPT_DOMAIN(_helpstr, cflags) \