mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh: Implement vshTable API to secret-list
Signed-off-by: Simon Kobyda <skobyda@redhat.com>
This commit is contained in:
parent
71029ef588
commit
cf12efe088
@ -35,6 +35,7 @@
|
|||||||
#include "virsecret.h"
|
#include "virsecret.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "virtime.h"
|
#include "virtime.h"
|
||||||
|
#include "vsh-table.h"
|
||||||
|
|
||||||
static virSecretPtr
|
static virSecretPtr
|
||||||
virshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
|
virshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
|
||||||
@ -507,6 +508,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
virshSecretListPtr list = NULL;
|
virshSecretListPtr list = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
vshTablePtr table = NULL;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "ephemeral"))
|
if (vshCommandOptBool(cmd, "ephemeral"))
|
||||||
flags |= VIR_CONNECT_LIST_SECRETS_EPHEMERAL;
|
flags |= VIR_CONNECT_LIST_SECRETS_EPHEMERAL;
|
||||||
@ -523,15 +525,17 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
if (!(list = virshSecretListCollect(ctl, flags)))
|
if (!(list = virshSecretListCollect(ctl, flags)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vshPrintExtra(ctl, " %-36s %s\n", _("UUID"), _("Usage"));
|
table = vshTableNew(_("UUID"), _("Usage"), NULL);
|
||||||
vshPrintExtra(ctl, "----------------------------------------"
|
if (!table)
|
||||||
"----------------------------------------\n");
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < list->nsecrets; i++) {
|
for (i = 0; i < list->nsecrets; i++) {
|
||||||
virSecretPtr sec = list->secrets[i];
|
virSecretPtr sec = list->secrets[i];
|
||||||
int usageType = virSecretGetUsageType(sec);
|
int usageType = virSecretGetUsageType(sec);
|
||||||
const char *usageStr = virSecretUsageTypeToString(usageType);
|
const char *usageStr = virSecretUsageTypeToString(usageType);
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
VIR_AUTOFREE(char *) usage = NULL;
|
||||||
|
|
||||||
if (virSecretGetUUIDString(sec, uuid) < 0) {
|
if (virSecretGetUUIDString(sec, uuid) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to get uuid of secret"));
|
vshError(ctl, "%s", _("Failed to get uuid of secret"));
|
||||||
@ -539,18 +543,26 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (usageType) {
|
if (usageType) {
|
||||||
vshPrint(ctl, " %-36s %s %s\n",
|
virBufferStrcat(&buf, usageStr, " ",
|
||||||
uuid, usageStr,
|
virSecretGetUsageID(sec), NULL);
|
||||||
virSecretGetUsageID(sec));
|
usage = virBufferContentAndReset(&buf);
|
||||||
|
if (!usage)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (vshTableRowAppend(table, uuid, usage, NULL) < 0)
|
||||||
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
vshPrint(ctl, " %-36s %s\n",
|
if (vshTableRowAppend(table, uuid, _("Unused"), NULL) < 0)
|
||||||
uuid, _("Unused"));
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vshTablePrintToStdout(table, ctl);
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
vshTableFree(table);
|
||||||
virshSecretListFree(list);
|
virshSecretListFree(list);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user