summaryrefslogtreecommitdiff
path: root/libpod/runtime_pod.go
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-07-11 16:27:52 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-12 22:13:52 +0000
commita2dde5a50d21f8857a57d412a8a1c4c8f731a8d1 (patch)
treec42c262d2bd9b3fb1f272168f63719386241d74e /libpod/runtime_pod.go
parent4f699db8dad05b770b4e02d3de67137517c3463b (diff)
downloadpodman-a2dde5a50d21f8857a57d412a8a1c4c8f731a8d1.tar.gz
podman-a2dde5a50d21f8857a57d412a8a1c4c8f731a8d1.tar.bz2
podman-a2dde5a50d21f8857a57d412a8a1c4c8f731a8d1.zip
Added created time to pod state
Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1079 Approved by: rhatdan
Diffstat (limited to 'libpod/runtime_pod.go')
-rw-r--r--libpod/runtime_pod.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/libpod/runtime_pod.go b/libpod/runtime_pod.go
index 34925c2d5..f5a2b017b 100644
--- a/libpod/runtime_pod.go
+++ b/libpod/runtime_pod.go
@@ -2,6 +2,9 @@ package libpod
import (
"context"
+ "time"
+
+ "github.com/pkg/errors"
)
// Contains the public Runtime API for pods
@@ -93,3 +96,36 @@ func (r *Runtime) Pods(filters ...PodFilter) ([]*Pod, error) {
return podsFiltered, nil
}
+
+// GetAllPods retrieves all pods
+func (r *Runtime) GetAllPods() ([]*Pod, error) {
+ r.lock.RLock()
+ defer r.lock.RUnlock()
+
+ if !r.valid {
+ return nil, ErrRuntimeStopped
+ }
+
+ return r.state.AllPods()
+}
+
+// GetLatestPod returns a pod object of the latest created pod.
+func (r *Runtime) GetLatestPod() (*Pod, error) {
+ lastCreatedIndex := -1
+ var lastCreatedTime time.Time
+ pods, err := r.GetAllPods()
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to get all pods")
+ }
+ if len(pods) == 0 {
+ return nil, ErrNoSuchPod
+ }
+ for podIndex, pod := range pods {
+ createdTime := pod.config.CreatedTime
+ if createdTime.After(lastCreatedTime) {
+ lastCreatedTime = createdTime
+ lastCreatedIndex = podIndex
+ }
+ }
+ return pods[lastCreatedIndex], nil
+}