diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-02-14 16:42:13 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-02-22 14:49:36 +0000 |
commit | 0b4c8fc2bb9813175b85e71aefcf285448632e14 (patch) | |
tree | 6b63e1065f26a0e31e217ff592b26e8aa3363f36 /libpod | |
parent | b8d1ce03a142d386e88ed505c1895d50b47448a5 (diff) | |
download | podman-0b4c8fc2bb9813175b85e71aefcf285448632e14.tar.gz podman-0b4c8fc2bb9813175b85e71aefcf285448632e14.tar.bz2 podman-0b4c8fc2bb9813175b85e71aefcf285448632e14.zip |
Add pod status command
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #361
Approved by: rhatdan
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/pod.go | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/libpod/pod.go b/libpod/pod.go index 8af76d5cb..6e4f67931 100644 --- a/libpod/pod.go +++ b/libpod/pod.go @@ -121,7 +121,35 @@ func (p *Pod) AllContainers() ([]*Container, error) { } // Status gets the status of all containers in the pod -// TODO This should return a summary of the states of all containers in the pod -func (p *Pod) Status() error { - return ErrNotImplemented +// Returns a map of Container ID to Container Status +func (p *Pod) Status() (map[string]ContainerStatus, error) { + p.lock.Lock() + defer p.lock.Unlock() + + if !p.valid { + return nil, ErrPodRemoved + } + + allCtrs, err := p.runtime.state.PodContainers(p) + if err != nil { + return nil, err + } + + // We need to lock all the containers + for _, ctr := range allCtrs { + ctr.lock.Lock() + defer ctr.lock.Unlock() + } + + // Now that all containers are locked, get their status + status := make(map[string]ContainerStatus, len(allCtrs)) + for _, ctr := range allCtrs { + if err := ctr.syncContainer(); err != nil { + return nil, err + } + + status[ctr.ID()] = ctr.state.State + } + + return status, nil } |