diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-02-22 21:12:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-22 21:12:49 +0100 |
commit | c757cb23ca15634077a8b9fa33aba7abd1c8249b (patch) | |
tree | cf98450129274946d9a79d321755d76d115ee3ba /libpod | |
parent | 8039ccf4d560acbc308066cf8996bc4e6167a4a9 (diff) | |
parent | bc6b4aa39c9156f31a5d370b19e91f42e0f14181 (diff) | |
download | podman-c757cb23ca15634077a8b9fa33aba7abd1c8249b.tar.gz podman-c757cb23ca15634077a8b9fa33aba7abd1c8249b.tar.bz2 podman-c757cb23ca15634077a8b9fa33aba7abd1c8249b.zip |
Merge pull request #2402 from baude/remotepodinspect
podman-remote pod inspect|exists
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/adapter/pods.go | 16 | ||||
-rw-r--r-- | libpod/adapter/pods_remote.go | 60 |
2 files changed, 73 insertions, 3 deletions
diff --git a/libpod/adapter/pods.go b/libpod/adapter/pods.go index 59642c42e..9841c20c0 100644 --- a/libpod/adapter/pods.go +++ b/libpod/adapter/pods.go @@ -36,3 +36,19 @@ func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValue } return podids, errs } + +// GetLatestPod gets the latest pod and wraps it in an adapter pod +func (r *LocalRuntime) GetLatestPod() (*Pod, error) { + pod := Pod{} + p, err := r.Runtime.GetLatestPod() + pod.Pod = p + return &pod, err +} + +// LookupPod gets a pod by name or id and wraps it in an adapter pod +func (r *LocalRuntime) LookupPod(nameOrID string) (*Pod, error) { + pod := Pod{} + p, err := r.Runtime.LookupPod(nameOrID) + pod.Pod = p + return &pod, err +} diff --git a/libpod/adapter/pods_remote.go b/libpod/adapter/pods_remote.go index 3fb147f48..57c78821f 100644 --- a/libpod/adapter/pods_remote.go +++ b/libpod/adapter/pods_remote.go @@ -4,10 +4,13 @@ package adapter import ( "context" + "encoding/json" "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/varlink" "github.com/containers/libpod/libpod" + "github.com/pkg/errors" + "github.com/ulule/deepcopier" ) // Pod ... @@ -16,11 +19,13 @@ type Pod struct { } type remotepod struct { - config *libpod.PodConfig - state *libpod.PodInspectState - Runtime *LocalRuntime + config *libpod.PodConfig + state *libpod.PodInspectState + containers []libpod.PodContainerInfo + Runtime *LocalRuntime } +// RemovePods removes one or more based on the cli context. func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValues) ([]string, []error) { var ( rmErrs []error @@ -42,3 +47,52 @@ func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValue } return rmPods, rmErrs } + +// Inspect looks up a pod by name or id and embeds its data into a remote pod +// object. +func (r *LocalRuntime) Inspect(nameOrID string) (*Pod, error) { + reply, err := iopodman.PodStateData().Call(r.Conn, nameOrID) + if err != nil { + return nil, err + } + data := libpod.PodInspect{} + if err := json.Unmarshal([]byte(reply), &data); err != nil { + return nil, err + } + pod := Pod{} + pod.Runtime = r + pod.config = data.Config + pod.state = data.State + pod.containers = data.Containers + return &pod, nil +} + +// GetLatestPod gets the latest pod and wraps it in an adapter pod +func (r *LocalRuntime) GetLatestPod() (*Pod, error) { + reply, err := iopodman.GetPodsByContext().Call(r.Conn, false, true, nil) + if err != nil { + return nil, err + } + if len(reply) > 0 { + return r.Inspect(reply[0]) + } + return nil, errors.New("no pods exist") +} + +// LookupPod gets a pod by name or ID and wraps it in an adapter pod +func (r *LocalRuntime) LookupPod(nameOrID string) (*Pod, error) { + return r.Inspect(nameOrID) +} + +// Inspect, like libpod pod inspect, returns a libpod.PodInspect object from +// the data of a remotepod data struct +func (p *Pod) Inspect() (*libpod.PodInspect, error) { + config := new(libpod.PodConfig) + deepcopier.Copy(p.remotepod.config).To(config) + inspectData := libpod.PodInspect{ + Config: config, + State: p.remotepod.state, + Containers: p.containers, + } + return &inspectData, nil +} |