]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Add timestamps to network events
authorAndrea Bolognani <abologna@redhat.com>
Fri, 8 Jan 2016 10:50:55 +0000 (11:50 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 11 Jan 2016 11:45:21 +0000 (12:45 +0100)
Implement a --timestamp option for 'virsh net-event', similar to the
one for 'virsh event'.

When the option is used, the human-readable timestamp will be printed
before the message.

tools/virsh-network.c

index bd89c11a791326d5de42e20ec63f52e48fc38a83..3eb1160078c0f6b18c68c4d23cc65849e363b314 100644 (file)
@@ -31,6 +31,7 @@
 #include "viralloc.h"
 #include "virfile.h"
 #include "virstring.h"
+#include "virtime.h"
 #include "conf/network_conf.h"
 
 virNetworkPtr
@@ -1181,6 +1182,7 @@ virshNetworkEventToString(int event)
 struct virshNetEventData {
     vshControl *ctl;
     bool loop;
+    bool timestamp;
     int count;
 };
 typedef struct virshNetEventData virshNetEventData;
@@ -1201,8 +1203,21 @@ vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
 
     if (!data->loop && data->count)
         return;
-    vshPrint(data->ctl, _("event 'lifecycle' for network %s: %s\n"),
-             virNetworkGetName(net), virshNetworkEventToString(event));
+
+    if (data->timestamp) {
+        char timestamp[VIR_TIME_STRING_BUFLEN];
+
+        if (virTimeStringNowRaw(timestamp) < 0)
+            timestamp[0] = '\0';
+
+        vshPrint(data->ctl, _("%s: event 'lifecycle' for network %s: %s\n"),
+                 timestamp,
+                 virNetworkGetName(net), virshNetworkEventToString(event));
+    } else {
+        vshPrint(data->ctl, _("event 'lifecycle' for network %s: %s\n"),
+                 virNetworkGetName(net), virshNetworkEventToString(event));
+    }
+
     data->count++;
     if (!data->loop)
         vshEventDone(data->ctl);
@@ -1239,6 +1254,10 @@ static const vshCmdOptDef opts_network_event[] = {
      .type = VSH_OT_BOOL,
      .help = N_("list valid event types")
     },
+    {.name = "timestamp",
+     .type = VSH_OT_BOOL,
+     .help = N_("show timestamp for each printed event")
+    },
     {.name = NULL}
 };
 
@@ -1275,6 +1294,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
 
     data.ctl = ctl;
     data.loop = vshCommandOptBool(cmd, "loop");
+    data.timestamp = vshCommandOptBool(cmd, "timestamp");
     data.count = 0;
     if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
         return false;