diff options
author | baude <bbaude@redhat.com> | 2018-05-04 10:39:34 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-05-08 15:44:38 +0000 |
commit | 21ebdb558cb939176d862e12bec99f34a1e5d4ba (patch) | |
tree | 537d4aef6fade4a1f436589caec9b72527436243 /pkg | |
parent | bb2d5759d444a15952955564596aa0ba2201b5c6 (diff) | |
download | podman-21ebdb558cb939176d862e12bec99f34a1e5d4ba.tar.gz podman-21ebdb558cb939176d862e12bec99f34a1e5d4ba.tar.bz2 podman-21ebdb558cb939176d862e12bec99f34a1e5d4ba.zip |
Allow streaming on some varlink container methods
The following methods should support streaming requests from the client:
* GetContainerLogs
A reference for a python stream implementation can be found here:
https://github.com/varlink/python/blob/master/varlink/tests/test_orgexamplemore.py#L29-L42
Signed-off-by: baude <bbaude@redhat.com>
Closes: #724
Approved by: mheon
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/varlinkapi/containers.go | 33 | ||||
-rw-r--r-- | pkg/varlinkapi/system.go | 2 |
2 files changed, 31 insertions, 4 deletions
diff --git a/pkg/varlinkapi/containers.go b/pkg/varlinkapi/containers.go index ece33556b..79eea4aa7 100644 --- a/pkg/varlinkapi/containers.go +++ b/pkg/varlinkapi/containers.go @@ -4,8 +4,10 @@ import ( "bufio" "encoding/json" "fmt" + "io" "os" "syscall" + "time" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/batchcontainer" @@ -117,6 +119,7 @@ func (i *LibpodAPI) ListContainerProcesses(call ioprojectatomicpodman.VarlinkCal if err != nil { return call.ReplyErrorOccurred(err.Error()) } + return call.ReplyListContainerProcesses(psOutput) } @@ -148,12 +151,36 @@ func (i *LibpodAPI) GetContainerLogs(call ioprojectatomicpodman.VarlinkCall, nam } defer file.Close() reader := bufio.NewReader(file) + if call.WantsMore() { + call.Continues = true + } for { line, err := reader.ReadString('\n') - if err != nil { - break + // We've read the entire file + if err == io.EOF { + if !call.WantsMore() { + // If this is a non-following log request, we return what we have + break + } else { + // If we want to follow, return what we have, wipe the slice, and make + // sure the container is still running before iterating. + call.ReplyGetContainerLogs(logs) + logs = []string{} + time.Sleep(1 * time.Second) + state, err := ctr.State() + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + if state != libpod.ContainerStateRunning && state != libpod.ContainerStatePaused { + return call.ReplyErrorOccurred(fmt.Sprintf("%s is no longer running", ctr.ID())) + } + + } + } else if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } else { + logs = append(logs, line) } - logs = append(logs, line) } return call.ReplyGetContainerLogs(logs) } diff --git a/pkg/varlinkapi/system.go b/pkg/varlinkapi/system.go index 976dfc682..418db6445 100644 --- a/pkg/varlinkapi/system.go +++ b/pkg/varlinkapi/system.go @@ -1,7 +1,7 @@ package varlinkapi import ( - ioprojectatomicpodman "github.com/projectatomic/libpod/cmd/podman/varlink" + "github.com/projectatomic/libpod/cmd/podman/varlink" "github.com/projectatomic/libpod/libpod" ) |