提交 bab521d8 编写于 作者: M Michal Privoznik

virsh: Introduce virshSecretUUIDCompleter

This is a slight change from previous patches since virSecret
does not have a name only UUID strings.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 2ba76e5c
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册