[PATCH] virsh: Separate 'create'/'modify' message for secret-define

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The current message of secret-define always be:
Secret 09a9736f-eedb-449c-9983-80d0ab67393f created

even you just modify the secret, perhaps this may puzzle
uses. Now this patch make the modify action output message
like this:
Secret f2d1bafc-ac58-4a47-93e4-47723686fef5 modified

Signed-off-by: Li Yang <liyang.fnst@xxxxxxxxxxxxxx>
---
 tools/virsh-secret.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index 10d5db3..d1cbe04 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -39,6 +39,7 @@
 #include "virutil.h"
 #include "virxml.h"
 #include "conf/secret_conf.h"
+#include "viruuid.h"
 
 static virSecretPtr
 vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
@@ -96,6 +97,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
     char *buffer;
     virSecretPtr res;
     char uuid[VIR_UUID_STRING_BUFLEN];
+    virSecretDefPtr new_attrs;
     bool ret = false;
 
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -104,6 +106,12 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
+    new_attrs = virSecretDefParseString(buffer);
+    if (new_attrs == NULL){
+        VIR_FREE(buffer);
+        return false;
+    }
+
     if (!(res = virSecretDefineXML(ctl->conn, buffer, 0))) {
         vshError(ctl, _("Failed to set attributes from %s"), from);
         goto cleanup;
@@ -114,10 +122,16 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    vshPrint(ctl, _("Secret %s created\n"), uuid);
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+    virUUIDFormat(new_attrs->uuid, uuidstr);
+    if (memcmp(uuid, uuidstr, VIR_UUID_BUFLEN) == 0)
+        vshPrint(ctl, _("Secret %s modified\n"), uuid);
+    else
+        vshPrint(ctl, _("Secret %s created\n"), uuid);
     ret = true;
 
  cleanup:
+    VIR_FREE(new_attrs);
     VIR_FREE(buffer);
     if (res)
         virSecretFree(res);
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]