summaryrefslogtreecommitdiff
path: root/pkg/adapter/containers.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-03-04 03:58:47 -0800
committerGitHub <noreply@github.com>2019-03-04 03:58:47 -0800
commitd63c8b00321f7e1d7c3cbfe3d1a57c9283d10d37 (patch)
tree93f6845030bd591e730ae315a6f3c47cc6e87dc0 /pkg/adapter/containers.go
parentf3a3d8e28e4b8ec06dd11ec156c10e243165f19d (diff)
parent4d13a80fa46ce57e3c889934536320525338b3a4 (diff)
downloadpodman-d63c8b00321f7e1d7c3cbfe3d1a57c9283d10d37.tar.gz
podman-d63c8b00321f7e1d7c3cbfe3d1a57c9283d10d37.tar.bz2
podman-d63c8b00321f7e1d7c3cbfe3d1a57c9283d10d37.zip
Merge pull request #2364 from jwhonce/wip/remote_stop
Support podman-remote stop container
Diffstat (limited to 'pkg/adapter/containers.go')
-rw-r--r--pkg/adapter/containers.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
new file mode 100644
index 000000000..b0c75cf49
--- /dev/null
+++ b/pkg/adapter/containers.go
@@ -0,0 +1,72 @@
+// +build !remoteclient
+
+package adapter
+
+import (
+ "context"
+
+ "github.com/containers/libpod/cmd/podman/cliconfig"
+ "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/adapter/shortcuts"
+ "github.com/pkg/errors"
+)
+
+// GetLatestContainer gets the latest Container and wraps it in an adapter Container
+func (r *LocalRuntime) GetLatestContainer() (*Container, error) {
+ Container := Container{}
+ c, err := r.Runtime.GetLatestContainer()
+ Container.Container = c
+ return &Container, err
+}
+
+// GetAllContainers gets all Containers and wraps each one in an adapter Container
+func (r *LocalRuntime) GetAllContainers() ([]*Container, error) {
+ var containers []*Container
+ allContainers, err := r.Runtime.GetAllContainers()
+ if err != nil {
+ return nil, err
+ }
+
+ for _, c := range allContainers {
+ containers = append(containers, &Container{c})
+ }
+ return containers, nil
+}
+
+// LookupContainer gets a Container by name or id and wraps it in an adapter Container
+func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
+ ctr, err := r.Runtime.LookupContainer(idOrName)
+ if err != nil {
+ return nil, err
+ }
+ return &Container{ctr}, nil
+}
+
+// StopContainers stops container(s) based on CLI inputs.
+// Returns list of successful id(s), map of failed id(s) + error, or error not from container
+func (r *LocalRuntime) StopContainers(ctx context.Context, cli *cliconfig.StopValues) ([]string, map[string]error, error) {
+ timeout := uint(0)
+ if cli.Flags().Changed("timeout") {
+ timeout = uint(cli.Timeout)
+ }
+
+ var (
+ ok = []string{}
+ failures = map[string]error{}
+ )
+
+ ctrs, err := shortcuts.GetContainersByContext(cli.All, cli.Latest, cli.InputArgs, r.Runtime)
+ if err != nil {
+ return ok, failures, err
+ }
+
+ for _, c := range ctrs {
+ err := c.StopWithTimeout(timeout)
+ if err != nil && errors.Cause(err) != libpod.ErrCtrStopped {
+ failures[c.ID()] = err
+ } else {
+ ok = append(ok, c.ID())
+ }
+ }
+ return ok, failures, nil
+}