[PATCH v2] 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 |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index 10d5db3..47974fe 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -96,6 +96,8 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
     char *buffer;
     virSecretPtr res;
     char uuid[VIR_UUID_STRING_BUFLEN];
+    virSecretDefPtr new_attrs;
+    virSecretPtr new_res;
     bool ret = false;
 
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -104,6 +106,14 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
+    if (!(new_attrs = virSecretDefParseString(buffer))) {
+        VIR_FREE(buffer);
+        return false;
+    }
+
+    new_res = virSecretLookupByUUID(ctl->conn, new_attrs->uuid);
+    new_attrs = NULL;
+
     if (!(res = virSecretDefineXML(ctl->conn, buffer, 0))) {
         vshError(ctl, _("Failed to set attributes from %s"), from);
         goto cleanup;
@@ -114,13 +124,19 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    vshPrint(ctl, _("Secret %s created\n"), uuid);
+    if (new_res == NULL)
+        vshPrint(ctl, _("Secret %s created\n"), uuid);
+    else
+        vshPrint(ctl, _("Secret %s modified\n"), uuid);
     ret = true;
 
  cleanup:
     VIR_FREE(buffer);
+    virSecretDefFree(new_attrs);
     if (res)
         virSecretFree(res);
+    if (new_res)
+        virSecretFree(new_res);
     return ret;
 }
 
-- 
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]