From 13f004aec5c70ca5be9f6c134566abd1e62ea660 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 13 Dec 2017 22:02:15 -0500 Subject: Add ability to retrieve a pod's container from the state Signed-off-by: Matthew Heon Closes: #229 Approved by: rhatdan --- libpod/in_memory_state.go | 14 ++++++++++++++ libpod/sql_state.go | 5 +++++ libpod/state.go | 2 ++ 3 files changed, 21 insertions(+) (limited to 'libpod') diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go index b4e224d77..93c61537f 100644 --- a/libpod/in_memory_state.go +++ b/libpod/in_memory_state.go @@ -284,6 +284,20 @@ func (s *InMemoryState) HasPod(id string) (bool, error) { return ok, nil } +// PodContainers retrieves the containers from a pod given the pod's full ID +func (s *InMemoryState) PodContainers(id string) ([]*Container, error) { + if id == "" { + return nil, ErrEmptyID + } + + pod, ok := s.pods[id] + if !ok { + return nil, errors.Wrapf(ErrNoSuchPod, "no pod with ID %s found", id) + } + + return pod.GetContainers() +} + // AddPod adds a given pod to the state // Only empty pods can be added to the state func (s *InMemoryState) AddPod(pod *Pod) error { diff --git a/libpod/sql_state.go b/libpod/sql_state.go index 4abce8576..f67fc0e2c 100644 --- a/libpod/sql_state.go +++ b/libpod/sql_state.go @@ -836,6 +836,11 @@ func (s *SQLState) HasPod(id string) (bool, error) { return false, ErrNotImplemented } +// PodContainers returns all the containers in a pod given the pod's full ID +func (s *SQLState) PodContainers(id string) ([]*Container, error) { + return nil, ErrNotImplemented +} + // AddPod adds a pod to the state // Only empty pods can be added to the state func (s *SQLState) AddPod(pod *Pod) error { diff --git a/libpod/state.go b/libpod/state.go index 63865a541..95012e586 100644 --- a/libpod/state.go +++ b/libpod/state.go @@ -44,6 +44,8 @@ type State interface { LookupPod(idOrName string) (*Pod, error) // Checks if a pod with the given ID is present in the state HasPod(id string) (bool, error) + // Get all the containers in a pod. Accepts full ID of pod. + PodContainers(id string) ([]*Container, error) // Adds pod to state // Only empty pods can be added to the state AddPod(pod *Pod) error -- cgit v1.2.3-54-g00ecf