summaryrefslogtreecommitdiff
path: root/cmd/podman/shared/pod.go
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-08-14 17:16:22 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-16 20:31:50 +0000
commit8d5e0108d7c8b69abb9821bfe55475ae5d663b3a (patch)
tree6d8fa9c82a9181fad919bd797f64fe46440e7a4e /cmd/podman/shared/pod.go
parent0059989783851ec536faf8a290eea863148dcb6c (diff)
downloadpodman-8d5e0108d7c8b69abb9821bfe55475ae5d663b3a.tar.gz
podman-8d5e0108d7c8b69abb9821bfe55475ae5d663b3a.tar.bz2
podman-8d5e0108d7c8b69abb9821bfe55475ae5d663b3a.zip
Change batchcontainer to shared
To better reflect it's usage: to share functions between podman and varlink. Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1275 Approved by: mheon
Diffstat (limited to 'cmd/podman/shared/pod.go')
-rw-r--r--cmd/podman/shared/pod.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/cmd/podman/shared/pod.go b/cmd/podman/shared/pod.go
new file mode 100644
index 000000000..50c642d59
--- /dev/null
+++ b/cmd/podman/shared/pod.go
@@ -0,0 +1,62 @@
+package shared
+
+import (
+ "github.com/projectatomic/libpod/libpod"
+)
+
+const (
+ stopped = "Stopped"
+ running = "Running"
+ paused = "Paused"
+ exited = "Exited"
+ errored = "Error"
+ created = "Created"
+)
+
+// GetPodStatus determines the status of the pod based on the
+// statuses of the containers in the pod.
+// Returns a string representation of the pod status
+func GetPodStatus(pod *libpod.Pod) (string, error) {
+ ctrStatuses, err := pod.Status()
+ if err != nil {
+ return errored, err
+ }
+ ctrNum := len(ctrStatuses)
+ if ctrNum == 0 {
+ return created, nil
+ }
+ statuses := map[string]int{
+ stopped: 0,
+ running: 0,
+ paused: 0,
+ created: 0,
+ errored: 0,
+ }
+ for _, ctrStatus := range ctrStatuses {
+ switch ctrStatus {
+ case libpod.ContainerStateStopped:
+ statuses[stopped]++
+ case libpod.ContainerStateRunning:
+ statuses[running]++
+ case libpod.ContainerStatePaused:
+ statuses[paused]++
+ case libpod.ContainerStateCreated, libpod.ContainerStateConfigured:
+ statuses[created]++
+ default:
+ statuses[errored]++
+ }
+ }
+
+ if statuses[running] > 0 {
+ return running, nil
+ } else if statuses[paused] == ctrNum {
+ return paused, nil
+ } else if statuses[stopped] == ctrNum {
+ return exited, nil
+ } else if statuses[stopped] > 0 {
+ return stopped, nil
+ } else if statuses[errored] > 0 {
+ return errored, nil
+ }
+ return created, nil
+}