Re: [libvirt] [PATCH 3/4] virsh: add event command, for lifecycle events
On Fri, Feb 14, 2014 at 05:21:40PM -0700, Eric Blake wrote: Add 'virsh event --list' and 'virsh event [dom] --event=name [--loop] [--timeout]'. Borrows somewhat from event-test.c, but defaults to a one-shot notification, and takes advantage of the event loop integration to allow Ctrl-C to interrupt the wait for an event. For now, this just does lifecycle events. * tools/virsh.pod (event): Document new command. * tools/virsh-domain.c (vshDomainEventToString) (vshDomainEventDetailToString, vshDomEventData) (vshEventLifecyclePrint, cmdEvent): New struct and functions. ACK Signed-off-by: Eric Blake ebl...@redhat.com --- tools/virsh-domain.c | 338 +++ tools/virsh.pod | 15 +++ 2 files changed, 353 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2c7bf66..3548131 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -10295,6 +10295,338 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd) return ret; } + +/* + * event command + */ +static const char * +vshDomainEventToString(int event) +{ +const char *ret = _(unknown); +switch ((virDomainEventType) event) { +case VIR_DOMAIN_EVENT_DEFINED: +ret = _(Defined); +break; +case VIR_DOMAIN_EVENT_UNDEFINED: +ret = _(Undefined); +break; +case VIR_DOMAIN_EVENT_STARTED: +ret = _(Started); +break; +case VIR_DOMAIN_EVENT_SUSPENDED: +ret = _(Suspended); +break; +case VIR_DOMAIN_EVENT_RESUMED: +ret = _(Resumed); +break; +case VIR_DOMAIN_EVENT_STOPPED: +ret = _(Stopped); +break; +case VIR_DOMAIN_EVENT_SHUTDOWN: +ret = _(Shutdown); +break; +case VIR_DOMAIN_EVENT_PMSUSPENDED: +ret = _(PMSuspended); +break; +case VIR_DOMAIN_EVENT_CRASHED: +ret = _(Crashed); +break; +case VIR_DOMAIN_EVENT_LAST: +break; +} +return ret; +} How about using VIR_ENUM ? We avoided it in the event-test.c file since we wanted it to be example code people can compile outside libvirt. Using enums would be fine for virsh though i think + +static const char * +vshDomainEventDetailToString(int event, int detail) +{ +const char *ret = _(unknown); +switch ((virDomainEventType) event) { +case VIR_DOMAIN_EVENT_DEFINED: +switch ((virDomainEventDefinedDetailType) detail) { +case VIR_DOMAIN_EVENT_DEFINED_ADDED: +ret = _(Added); +break; +case VIR_DOMAIN_EVENT_DEFINED_UPDATED: +ret = _(Updated); +break; +case VIR_DOMAIN_EVENT_DEFINED_LAST: +break; +} +break; +case VIR_DOMAIN_EVENT_UNDEFINED: +switch ((virDomainEventUndefinedDetailType) detail) { +case VIR_DOMAIN_EVENT_UNDEFINED_REMOVED: +ret = _(Removed); +break; +case VIR_DOMAIN_EVENT_UNDEFINED_LAST: +break; +} +break; +case VIR_DOMAIN_EVENT_STARTED: +switch ((virDomainEventStartedDetailType) detail) { +case VIR_DOMAIN_EVENT_STARTED_BOOTED: +ret = _(Booted); +break; +case VIR_DOMAIN_EVENT_STARTED_MIGRATED: +ret = _(Migrated); +break; +case VIR_DOMAIN_EVENT_STARTED_RESTORED: +ret = _(Restored); +break; +case VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT: +ret = _(Snapshot); +break; +case VIR_DOMAIN_EVENT_STARTED_WAKEUP: +ret = _(Event wakeup); +break; +case VIR_DOMAIN_EVENT_STARTED_LAST: +break; +} +break; +case VIR_DOMAIN_EVENT_SUSPENDED: +switch ((virDomainEventSuspendedDetailType) detail) { +case VIR_DOMAIN_EVENT_SUSPENDED_PAUSED: +ret = _(Paused); +break; +case VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED: +ret = _(Migrated); +break; +case VIR_DOMAIN_EVENT_SUSPENDED_IOERROR: +ret = _(I/O Error); +break; +case VIR_DOMAIN_EVENT_SUSPENDED_WATCHDOG: +ret = _(Watchdog); +break; +case VIR_DOMAIN_EVENT_SUSPENDED_RESTORED: +ret = _(Restored); +break; +case VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT: +ret = _(Snapshot); +break; +case VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR: +ret = _(API error); +break; +case VIR_DOMAIN_EVENT_SUSPENDED_LAST: +break; +} +break; +case VIR_DOMAIN_EVENT_RESUMED: +switch ((virDomainEventResumedDetailType) detail) { +case VIR_DOMAIN_EVENT_RESUMED_UNPAUSED: +ret = _(Unpaused); +break; +case
Re: [libvirt] [PATCH 3/4] virsh: add event command, for lifecycle events
On 02/20/2014 10:33 AM, Daniel P. Berrange wrote: On Fri, Feb 14, 2014 at 05:21:40PM -0700, Eric Blake wrote: Add 'virsh event --list' and 'virsh event [dom] --event=name [--loop] [--timeout]'. Borrows somewhat from event-test.c, but defaults to a one-shot notification, and takes advantage of the event loop integration to allow Ctrl-C to interrupt the wait for an event. For now, this just does lifecycle events. * tools/virsh.pod (event): Document new command. * tools/virsh-domain.c (vshDomainEventToString) (vshDomainEventDetailToString, vshDomEventData) (vshEventLifecyclePrint, cmdEvent): New struct and functions. ACK +case VIR_DOMAIN_EVENT_DEFINED: +ret = _(Defined); +break; How about using VIR_ENUM ? We avoided it in the event-test.c file since we wanted it to be example code people can compile outside libvirt. Using enums would be fine for virsh though i think VIR_ENUM doesn't allow _() translation. This output is human legible, so we want it to appear in the user's locale (see also vshDomainVcpuStateToString() and friends). +++ b/tools/virsh.pod +By default, tihs command is one-shot, and returns success once an event s/tihs/this/ Rare case of me spotting a typo in your code, instead of the reverse :-) Hey - I have to inject errors somewhere, to make the review worthwhile, right? :) Fixed, and will push the series shortly as well as crank out patch 5/4 for the remaining events. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/4] virsh: add event command, for lifecycle events
On Thu, Feb 20, 2014 at 11:06:55AM -0700, Eric Blake wrote: On 02/20/2014 10:33 AM, Daniel P. Berrange wrote: On Fri, Feb 14, 2014 at 05:21:40PM -0700, Eric Blake wrote: Add 'virsh event --list' and 'virsh event [dom] --event=name [--loop] [--timeout]'. Borrows somewhat from event-test.c, but defaults to a one-shot notification, and takes advantage of the event loop integration to allow Ctrl-C to interrupt the wait for an event. For now, this just does lifecycle events. * tools/virsh.pod (event): Document new command. * tools/virsh-domain.c (vshDomainEventToString) (vshDomainEventDetailToString, vshDomEventData) (vshEventLifecyclePrint, cmdEvent): New struct and functions. ACK +case VIR_DOMAIN_EVENT_DEFINED: +ret = _(Defined); +break; How about using VIR_ENUM ? We avoided it in the event-test.c file since we wanted it to be example code people can compile outside libvirt. Using enums would be fine for virsh though i think VIR_ENUM doesn't allow _() translation. This output is human legible, so we want it to appear in the user's locale (see also vshDomainVcpuStateToString() and friends). This is what the N_() macro is for though isn't it. Marks the string for translation, but actual gettext call is done at time of use instead. Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/4] virsh: add event command, for lifecycle events
On 02/20/2014 11:14 AM, Daniel P. Berrange wrote: +case VIR_DOMAIN_EVENT_DEFINED: +ret = _(Defined); +break; How about using VIR_ENUM ? We avoided it in the event-test.c file since we wanted it to be example code people can compile outside libvirt. Using enums would be fine for virsh though i think VIR_ENUM doesn't allow _() translation. This output is human legible, so we want it to appear in the user's locale (see also vshDomainVcpuStateToString() and friends). This is what the N_() macro is for though isn't it. Marks the string for translation, but actual gettext call is done at time of use instead. That should work - I'll do it as a separate patch, since there's a lot more places that can be cleaned up. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list