[PATCH 7/8] virsh: Introduce virshSecretUUIDCompleter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a slight change from previous patches since virSecret
does not have a name only UUID strings.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tools/virsh-completer.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh-completer.h |  4 ++++
 tools/virsh-secret.c    | 15 ++++++++++-----
 3 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 9e6f086c0..7332fa97a 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -438,3 +438,49 @@ virshNWFilterNameCompleter(vshControl *ctl,
     VIR_FREE(ret);
     return NULL;
 }
+
+
+char **
+virshSecretUUIDCompleter(vshControl *ctl,
+                         const vshCmd *cmd ATTRIBUTE_UNUSED,
+                         unsigned int flags)
+{
+    virshControlPtr priv = ctl->privData;
+    virSecretPtr *secrets = NULL;
+    int nsecrets = 0;
+    size_t i = 0;
+    char **ret = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+        return NULL;
+
+    if ((nsecrets = virConnectListAllSecrets(priv->conn, &secrets, flags)) < 0)
+        return NULL;
+
+    if (VIR_ALLOC_N(ret, nsecrets + 1) < 0)
+        goto error;
+
+    for (i = 0; i < nsecrets; i++) {
+        char uuid[VIR_UUID_STRING_BUFLEN];
+
+        if (virSecretGetUUIDString(secrets[i], uuid) < 0 ||
+            VIR_STRDUP(ret[i], uuid) < 0)
+            goto error;
+
+        virSecretFree(secrets[i]);
+    }
+    VIR_FREE(secrets);
+
+    return ret;
+
+ error:
+    for (; i < nsecrets; i++)
+        virSecretFree(secrets[i]);
+    VIR_FREE(secrets);
+    for (i = 0; i < nsecrets; i++)
+        VIR_FREE(ret[i]);
+    VIR_FREE(ret);
+    return NULL;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index 3c3b17f1e..0e518873c 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -62,4 +62,8 @@ char ** virshNWFilterNameCompleter(vshControl *ctl,
                                    const vshCmd *cmd,
                                    unsigned int flags);
 
+char ** virshSecretUUIDCompleter(vshControl *ctl,
+                                 const vshCmd *cmd,
+                                 unsigned int flags);
+
 #endif
diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index 52f067652..9e4ec61a8 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -132,7 +132,8 @@ static const vshCmdOptDef opts_secret_dumpxml[] = {
     {.name = "secret",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("secret UUID")
+     .help = N_("secret UUID"),
+     .completer = virshSecretUUIDCompleter,
     },
     {.name = NULL}
 };
@@ -177,7 +178,8 @@ static const vshCmdOptDef opts_secret_set_value[] = {
     {.name = "secret",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("secret UUID")
+     .help = N_("secret UUID"),
+     .completer = virshSecretUUIDCompleter,
     },
     {.name = "base64",
      .type = VSH_OT_DATA,
@@ -245,7 +247,8 @@ static const vshCmdOptDef opts_secret_get_value[] = {
     {.name = "secret",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("secret UUID")
+     .help = N_("secret UUID"),
+     .completer = virshSecretUUIDCompleter,
     },
     {.name = NULL}
 };
@@ -297,7 +300,8 @@ static const vshCmdOptDef opts_secret_undefine[] = {
     {.name = "secret",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("secret UUID")
+     .help = N_("secret UUID"),
+     .completer = virshSecretUUIDCompleter,
     },
     {.name = NULL}
 };
@@ -667,7 +671,8 @@ static const vshCmdInfo info_secret_event[] = {
 static const vshCmdOptDef opts_secret_event[] = {
     {.name = "secret",
      .type = VSH_OT_STRING,
-     .help = N_("filter by secret name or uuid")
+     .help = N_("filter by secret name or uuid"),
+     .completer = virshSecretUUIDCompleter,
     },
     {.name = "event",
      .type = VSH_OT_STRING,
-- 
2.13.6

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux