Blob Blame History Raw
From e387f0a8337a7a9acb0aec433f1f90a1c4cdeb80 Mon Sep 17 00:00:00 2001
Message-Id: <e387f0a8337a7a9acb0aec433f1f90a1c4cdeb80.1377873641.git.jdenemar@redhat.com>
From: John Ferlan <jferlan@redhat.com>
Date: Thu, 22 Aug 2013 16:56:23 -0400
Subject: [PATCH] virsh: Print cephx and iscsi usage

https://bugzilla.redhat.com/show_bug.cgi?id=1000155

When using virsh secret-list - if the secret types are cephx or iscsi,
then allow fetch/print of the usage information. Prior to the change
the following would print:

UUID                                 Usage
-----------------------------------------------------------
1b40a534-8301-45d5-b1aa-11894ebb1735 Unused
a5ba3efe-6adf-4a6a-b243-f010a043e314 Unused

Afterwards:

UUID                                 Usage
-----------------------------------------------------------
1b40a534-8301-45d5-b1aa-11894ebb1735 ceph ceph_example
a5ba3efe-6adf-4a6a-b243-f010a043e314 iscsi libvirtiscsi

(cherry picked from commit db1382f322841a7f8c877151644f49c147664fec)
---
 tools/virsh-secret.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index c4763e3..e849a79 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -38,6 +38,7 @@
 #include "virfile.h"
 #include "virutil.h"
 #include "virxml.h"
+#include "conf/secret_conf.h"
 
 static virSecretPtr
 vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
@@ -536,15 +537,10 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     for (i = 0; i < list->nsecrets; i++) {
         virSecretPtr sec = list->secrets[i];
-        const char *usageType = NULL;
-
-        switch (virSecretGetUsageType(sec)) {
-        case VIR_SECRET_USAGE_TYPE_VOLUME:
-            usageType = _("Volume");
-            break;
-        }
-
+        int usageType = virSecretGetUsageType(sec);
+        const char *usageStr = virSecretUsageTypeTypeToString(usageType);
         char uuid[VIR_UUID_STRING_BUFLEN];
+
         if (virSecretGetUUIDString(list->secrets[i], uuid) < 0) {
             vshError(ctl, "%s", _("Failed to get uuid of secret"));
             goto cleanup;
@@ -552,7 +548,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
         if (usageType) {
             vshPrint(ctl, "%-36s %s %s\n",
-                     uuid, usageType,
+                     uuid, usageStr,
                      virSecretGetUsageID(sec));
         } else {
             vshPrint(ctl, "%-36s %s\n",
-- 
1.8.3.2