diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index e95e7581d1c6f3bb1581a7e4e37f019da8d339e3..c06828df4ed93c53c3f49ab6b74c1d126365d3aa 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -432,3 +432,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 3c3b17f1e86b0a9958bfb49b3030b0e5d545b218..0e518873c5e2a7ade0482255ebdacb5c5d51f406 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 52f067652bd180ba0040f3f4d63c5fb6445043f7..9e4ec61a8807b7d09c693607ffe3f7cf95f4223f 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,