[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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 <eblake 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 VIR_DOMAIN_EVENT_RESUMED_MIGRATED:
> +            ret = _("Migrated");
> +            break;
> +        case VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT:
> +            ret = _("Snapshot");
> +            break;
> +        case VIR_DOMAIN_EVENT_RESUMED_LAST:
> +            break;
> +        }
> +        break;
> +    case VIR_DOMAIN_EVENT_STOPPED:
> +        switch ((virDomainEventStoppedDetailType) detail) {
> +        case VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN:
> +            ret = _("Shutdown");
> +            break;
> +        case VIR_DOMAIN_EVENT_STOPPED_DESTROYED:
> +            ret = _("Destroyed");
> +            break;
> +        case VIR_DOMAIN_EVENT_STOPPED_CRASHED:
> +            ret = _("Crashed");
> +            break;
> +        case VIR_DOMAIN_EVENT_STOPPED_MIGRATED:
> +            ret = _("Migrated");
> +            break;
> +        case VIR_DOMAIN_EVENT_STOPPED_SAVED:
> +            ret = _("Saved");
> +            break;
> +        case VIR_DOMAIN_EVENT_STOPPED_FAILED:
> +            ret = _("Failed");
> +            break;
> +        case VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT:
> +            ret = _("Snapshot");
> +            break;
> +        case VIR_DOMAIN_EVENT_STOPPED_LAST:
> +            break;
> +        }
> +        break;
> +    case VIR_DOMAIN_EVENT_SHUTDOWN:
> +        switch ((virDomainEventShutdownDetailType) detail) {
> +        case VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED:
> +            ret = _("Finished");
> +            break;
> +        case VIR_DOMAIN_EVENT_SHUTDOWN_LAST:
> +            break;
> +        }
> +        break;
> +    case VIR_DOMAIN_EVENT_PMSUSPENDED:
> +        switch ((virDomainEventPMSuspendedDetailType) detail) {
> +        case VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY:
> +            ret = _("Memory");
> +            break;
> +        case VIR_DOMAIN_EVENT_PMSUSPENDED_DISK:
> +            ret = _("Disk");
> +            break;
> +        case VIR_DOMAIN_EVENT_PMSUSPENDED_LAST:
> +            break;
> +        }
> +        break;
> +    case VIR_DOMAIN_EVENT_CRASHED:
> +        switch ((virDomainEventCrashedDetailType) detail) {
> +        case VIR_DOMAIN_EVENT_CRASHED_PANICKED:
> +            ret = _("Panicked");
> +            break;
> +        case VIR_DOMAIN_EVENT_CRASHED_LAST:
> +            break;
> +        }
> +        break;
> +    case VIR_DOMAIN_EVENT_LAST:
> +        break;
> +    }

And VIR_ENUM for each of the detail sets ?

> +    return ret;
> +}
> +

> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index f221475..0878778 100644
> --- a/tools/virsh.pod
> +++ 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 :-)

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 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]