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

Martin Kletzander mkletzan at redhat.com
Fri Apr 18 10:20:26 UTC 2014


On Fri, Apr 18, 2014 at 04:27:10AM -0400, Li Yang wrote:
>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;

You'll still print 'modified' if the new created secret has an uuid in
the file already, plus it does more parsing, etc.  Wouldn't it be
easier to just do s/created/defined/ ?

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140418/caae8d6e/attachment-0001.sig>


More information about the libvir-list mailing list