summaryrefslogtreecommitdiff
path: root/libpod/pod.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-08-08 13:08:22 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-09 11:06:32 +0000
commit06fafe4cd04f29ee19078d6e78fdd792f2c1a37e (patch)
tree858649113e849d6b6c179126eb3b8740b0d2ee9d /libpod/pod.go
parent879453eaf16675f732dd87fd250ccaaac72f4285 (diff)
downloadpodman-06fafe4cd04f29ee19078d6e78fdd792f2c1a37e.tar.gz
podman-06fafe4cd04f29ee19078d6e78fdd792f2c1a37e.tar.bz2
podman-06fafe4cd04f29ee19078d6e78fdd792f2c1a37e.zip
add podman pod inspect
first pass of podman pod inspect Signed-off-by: baude <bbaude@redhat.com> Closes: #1236 Approved by: rhatdan
Diffstat (limited to 'libpod/pod.go')
-rw-r--r--libpod/pod.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/libpod/pod.go b/libpod/pod.go
index 2ad4f7d0e..46182680a 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -10,6 +10,7 @@ import (
"github.com/docker/docker/pkg/stringid"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
+ "github.com/ulule/deepcopier"
)
// Pod represents a group of containers that are managed together.
@@ -59,6 +60,20 @@ type podState struct {
CgroupPath string
}
+// PodInspect represents the data we want to display for
+// podman pod inspect
+type PodInspect struct {
+ Config *PodConfig
+ State *podState
+ Containers []PodContainerInfo
+}
+
+// PodContainerInfo keeps information on a container in a pod
+type PodContainerInfo struct {
+ ID string `json:"id"`
+ State string `json:"state"`
+}
+
// ID retrieves the pod's ID
func (p *Pod) ID() string {
return p.config.ID
@@ -696,3 +711,38 @@ func (p *Pod) Status() (map[string]ContainerStatus, error) {
// TODO add pod batching
// Lock pod to avoid lock contention
// Store and lock all containers (no RemoveContainer in batch guarantees cache will not become stale)
+
+// Inspect returns a PodInspect struct to describe the pod
+func (p *Pod) Inspect() (*PodInspect, error) {
+ var (
+ podContainers []PodContainerInfo
+ )
+
+ containers, err := p.AllContainers()
+ if err != nil {
+ return &PodInspect{}, err
+ }
+ for _, c := range containers {
+ containerStatus := "unknown"
+ // Ignoring possible errors here because we dont want this to be
+ // catastrophic in nature
+ containerState, err := c.State()
+ if err == nil {
+ containerStatus = containerState.String()
+ }
+ pc := PodContainerInfo{
+ ID: c.ID(),
+ State: containerStatus,
+ }
+ podContainers = append(podContainers, pc)
+ }
+
+ config := new(PodConfig)
+ deepcopier.Copy(p.config).To(config)
+ inspectData := PodInspect{
+ Config: config,
+ State: p.state,
+ Containers: podContainers,
+ }
+ return &inspectData, nil
+}