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

Li Yang liyang.fnst at cn.fujitsu.com
Fri Apr 18 08:27:10 UTC 2014


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 at cn.fujitsu.com>
---
 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




More information about the libvir-list mailing list