mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
virsh: Introduce virshSecretUUIDCompleter
This is a slight change from previous patches since virSecret does not have a name only UUID strings. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
2ba76e5cc7
commit
bab521d837
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user