[libvirt] [PATCH 0/3] virsh: Implement and document --timeout everywhere

Jirka added a new --timestamp option to 'virsh event'[1], so I went ahead and updated the 'net-event' and 'qemu-monitor-event' virsh commands to support it as well. I've also updated the man page so that the new option is properly documented. Cheers. [1] https://www.redhat.com/archives/libvir-list/2015-December/msg00806.html Andrea Bolognani (3): virsh: Add timestamps to QEMU monitor events virsh: Add timestamps to network events virsh: Document the --timestamp option tools/virsh-domain.c | 22 ++++++++++++++++++++-- tools/virsh-network.c | 24 ++++++++++++++++++++++-- tools/virsh.pod | 15 +++++++++++++-- 3 files changed, 55 insertions(+), 6 deletions(-) -- 2.5.0

Implement a --timestamp option for 'virsh qemu-monitor-event', similar to the one for 'virsh event'. When the option is used, the human-readable timestamp will be printed before the message, and the timing information provided by QEMU will not be displayed. --- tools/virsh-domain.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index edbbc34..515ed36 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9157,6 +9157,7 @@ struct virshQemuEventData { vshControl *ctl; bool loop; bool pretty; + bool timestamp; int count; }; typedef struct virshQemuEventData virshQemuEventData; @@ -9177,8 +9178,20 @@ virshEventPrint(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainPtr dom, if (pretty && (str = virJSONValueToString(pretty, true))) details = str; } - vshPrint(data->ctl, "event %s at %lld.%06u for domain %s: %s\n", - event, seconds, micros, virDomainGetName(dom), NULLSTR(details)); + + if (data->timestamp) { + char timestamp[VIR_TIME_STRING_BUFLEN]; + + if (virTimeStringNowRaw(timestamp) < 0) + timestamp[0] = '\0'; + + vshPrint(data->ctl, "%s: event %s for domain %s: %s\n", + timestamp, event, virDomainGetName(dom), NULLSTR(details)); + } else { + vshPrint(data->ctl, "event %s at %lld.%06u for domain %s: %s\n", + event, seconds, micros, virDomainGetName(dom), NULLSTR(details)); + } + data->count++; if (!data->loop) vshEventDone(data->ctl); @@ -9225,6 +9238,10 @@ static const vshCmdOptDef opts_qemu_monitor_event[] = { .type = VSH_OT_BOOL, .help = N_("treat event case-insensitively") }, + {.name = "timestamp", + .type = VSH_OT_BOOL, + .help = N_("show timestamp for each printed event") + }, {.name = NULL} }; @@ -9248,6 +9265,7 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd) data.ctl = ctl; data.loop = vshCommandOptBool(cmd, "loop"); data.pretty = vshCommandOptBool(cmd, "pretty"); + data.timestamp = vshCommandOptBool(cmd, "timestamp"); data.count = 0; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; -- 2.5.0

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 | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index bd89c11..3eb1160 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -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; -- 2.5.0

The event, net-event and qemu-monitor-event virsh commands all support the --timestamp option now, but such option was not referenced in the man page. --- tools/virsh.pod | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index 9456db8..e830c59 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1370,7 +1370,7 @@ The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment variables, and defaults to C<vi>. =item B<event> {[I<domain>] { I<event> | I<--all> } [I<--loop>] -[I<--timeout> I<seconds>] | I<--list>} +[I<--timeout> I<seconds>] [I<--timestamp>] | I<--list>} Wait for a class of domain events to occur, and print appropriate details of events as they happen. The events can optionally be filtered by @@ -1386,6 +1386,9 @@ If I<--timeout> is specified, the command gives up waiting for events after I<seconds> have elapsed. With I<--loop>, the command prints all events until a timeout or interrupt key. +When I<--timestamp> is used, a human-readable timestamp will be printed +before the event. + =item B<iothreadinfo> I<domain> [[I<--live>] [I<--config>] | [I<--current>]] Display basic domain IOThreads information including the IOThread ID and @@ -2877,7 +2880,7 @@ The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment variables, and defaults to C<vi>. =item B<net-event> {[I<network>] I<event> [I<--loop>] [I<--timeout> -I<seconds>] | I<--list>} +I<seconds>] [I<--timestamp>] | I<--list>} Wait for a class of network events to occur, and print appropriate details of events as they happen. The events can optionally be filtered by @@ -2891,6 +2894,9 @@ If I<--timeout> is specified, the command gives up waiting for events after I<seconds> have elapsed. With I<--loop>, the command prints all events until a timeout or interrupt key. +When I<--timestamp> is used, a human-readable timestamp will be printed +before the event. + =item B<net-info> I<network> Returns basic information about the I<network> object. @@ -4074,6 +4080,7 @@ timeout. =item B<qemu-monitor-event> [I<domain>] [I<--event> I<event-name>] [I<--loop>] [I<--timeout> I<seconds>] [I<--pretty>] [I<--regex>] [I<--no-case>] +[I<--timestamp>] Wait for arbitrary QEMU monitor events to occur, and print out the details of events as they happen. The events can optionally be filtered @@ -4090,6 +4097,10 @@ after I<seconds> have elapsed. With I<--loop>, the command prints all events until a timeout or interrupt key. If I<--pretty> is specified, any JSON event details are pretty-printed for better legibility. +When I<--timestamp> is used, a human-readable timestamp will be printed +before the event, and the timing information provided by QEMU will be +omitted. + =item B<lxc-enter-namespace> I<domain> -- /path/to/binary [arg1, [arg2, ...]] Enter the namespace of I<domain> and execute the command C</path/to/binary> -- 2.5.0

On Fri, Jan 08, 2016 at 13:21:16 +0100, Andrea Bolognani wrote:
Jirka added a new --timestamp option to 'virsh event'[1], so I went ahead and updated the 'net-event' and 'qemu-monitor-event' virsh commands to support it as well.
I've also updated the man page so that the new option is properly documented.
Cheers.
[1] https://www.redhat.com/archives/libvir-list/2015-December/msg00806.html
Andrea Bolognani (3): virsh: Add timestamps to QEMU monitor events virsh: Add timestamps to network events virsh: Document the --timestamp option
tools/virsh-domain.c | 22 ++++++++++++++++++++-- tools/virsh-network.c | 24 ++++++++++++++++++++++-- tools/virsh.pod | 15 +++++++++++++-- 3 files changed, 55 insertions(+), 6 deletions(-)
ACK series Jirka

On Mon, 2016-01-11 at 12:28 +0100, Jiri Denemark wrote:
On Fri, Jan 08, 2016 at 13:21:16 +0100, Andrea Bolognani wrote:
Jirka added a new --timestamp option to 'virsh event'[1], so I went ahead and updated the 'net-event' and 'qemu-monitor-event' virsh commands to support it as well.
I've also updated the man page so that the new option is properly documented.
Cheers.
[1] https://www.redhat.com/archives/libvir-list/2015-December/msg00806.html
Andrea Bolognani (3): virsh: Add timestamps to QEMU monitor events virsh: Add timestamps to network events virsh: Document the --timestamp option
tools/virsh-domain.c | 22 ++++++++++++++++++++-- tools/virsh-network.c | 24 ++++++++++++++++++++++-- tools/virsh.pod | 15 +++++++++++++-- 3 files changed, 55 insertions(+), 6 deletions(-)
ACK series
Pushed, thanks :) -- Andrea Bolognani Software Engineer - Virtualization Team
participants (2)
-
Andrea Bolognani
-
Jiri Denemark