diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-03-11 18:04:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-11 18:04:51 -0700 |
commit | 300b53cffea54724132028a2a7da5f6c77cd546c (patch) | |
tree | 71d3c99b3342c81a6d70a722879bd9a8a1f1d259 /pkg/varlinkapi/events.go | |
parent | dcd253f2e4da25e7e5af33bef4de5529162a7c1b (diff) | |
parent | ca1e76ff632dec0b0e00e25f26677887ca8cc625 (diff) | |
download | podman-300b53cffea54724132028a2a7da5f6c77cd546c.tar.gz podman-300b53cffea54724132028a2a7da5f6c77cd546c.tar.bz2 podman-300b53cffea54724132028a2a7da5f6c77cd546c.zip |
Merge pull request #2527 from baude/events
Add event logging to libpod, even display to podman
Diffstat (limited to 'pkg/varlinkapi/events.go')
-rw-r--r-- | pkg/varlinkapi/events.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/pkg/varlinkapi/events.go b/pkg/varlinkapi/events.go new file mode 100644 index 000000000..d3fe3d65f --- /dev/null +++ b/pkg/varlinkapi/events.go @@ -0,0 +1,56 @@ +package varlinkapi + +import ( + "fmt" + "time" + + "github.com/containers/libpod/cmd/podman/shared" + "github.com/containers/libpod/cmd/podman/varlink" + "github.com/containers/libpod/libpod/events" +) + +// GetEvents is a remote endpoint to get events from the event log +func (i *LibpodAPI) GetEvents(call iopodman.VarlinkCall, filter []string, since string, stream bool, until string) error { + var ( + fromStart bool + eventsError error + event *events.Event + ) + if call.WantsMore() { + call.Continues = true + } + filters, err := shared.GenerateEventOptions(filter, since, until) + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + if len(since) > 0 || len(until) > 0 { + fromStart = true + } + eventChannel := make(chan *events.Event) + go func() { + eventsError = i.Runtime.Events(fromStart, stream, filters, eventChannel) + }() + if eventsError != nil { + return call.ReplyErrorOccurred(err.Error()) + } + for { + event = <-eventChannel + if event == nil { + call.Continues = false + break + } + call.ReplyGetEvents(iopodman.Event{ + Id: event.ID, + Image: event.Image, + Name: event.Name, + Status: fmt.Sprintf("%s", event.Status), + Time: event.Time.Format(time.RFC3339Nano), + Type: fmt.Sprintf("%s", event.Type), + }) + if !call.Continues { + // For a one-shot on events, we break out here + break + } + } + return call.ReplyGetEvents(iopodman.Event{}) +} |