aboutsummaryrefslogtreecommitdiff
path: root/pkg/adapter/containers.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2019-02-18 16:01:31 -0700
committerJhon Honce <jhonce@redhat.com>2019-03-02 08:57:20 -0700
commit4d13a80fa46ce57e3c889934536320525338b3a4 (patch)
tree8d3d5bd4f0209aa8ce4e3371478e6edc305209e6 /pkg/adapter/containers.go
parent9adcda73892fa0a33cbdf971ad97cf079e8e425f (diff)
downloadpodman-4d13a80fa46ce57e3c889934536320525338b3a4.tar.gz
podman-4d13a80fa46ce57e3c889934536320525338b3a4.tar.bz2
podman-4d13a80fa46ce57e3c889934536320525338b3a4.zip
Support podman-remote stop container(s)
* Clean up adapter code * Add GetContainersByContext to Varlink API * Add missing comments * Restore save command * Restore error type mapping when using varlink Signed-off-by: Jhon Honce <jhonce@redhat.com>
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
+}