summaryrefslogtreecommitdiff
path: root/pkg/adapter/containers.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-04-18 14:17:41 -0700
committerGitHub <noreply@github.com>2019-04-18 14:17:41 -0700
commite4947e5fd699f584cb815a4f4fd92f22b62f2c8a (patch)
tree525468fc942fcf473ad1df3722bbf05ea03f3c7b /pkg/adapter/containers.go
parent4d45f5180f778bf3a298bf061ca2c0dba0d4bfad (diff)
parent55e630e7876557ebd2a44e81fa357aab9efbb793 (diff)
downloadpodman-e4947e5fd699f584cb815a4f4fd92f22b62f2c8a.tar.gz
podman-e4947e5fd699f584cb815a4f4fd92f22b62f2c8a.tar.bz2
podman-e4947e5fd699f584cb815a4f4fd92f22b62f2c8a.zip
Merge pull request #2948 from baude/remotepause
podman-remote pause|unpause
Diffstat (limited to 'pkg/adapter/containers.go')
-rw-r--r--pkg/adapter/containers.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index 063ecfbfb..5279f11b2 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -607,3 +607,90 @@ func (r *LocalRuntime) Start(ctx context.Context, c *cliconfig.StartValues, sigP
}
return exitCode, lastError
}
+
+// PauseContainers removes container(s) based on CLI inputs.
+func (r *LocalRuntime) PauseContainers(ctx context.Context, cli *cliconfig.PauseValues) ([]string, map[string]error, error) {
+ var (
+ ok = []string{}
+ failures = map[string]error{}
+ ctrs []*libpod.Container
+ err error
+ )
+
+ maxWorkers := shared.DefaultPoolSize("pause")
+ if cli.GlobalIsSet("max-workers") {
+ maxWorkers = cli.GlobalFlags.MaxWorks
+ }
+ logrus.Debugf("Setting maximum rm workers to %d", maxWorkers)
+
+ if cli.All {
+ ctrs, err = r.GetRunningContainers()
+ } else {
+ ctrs, err = shortcuts.GetContainersByContext(false, false, cli.InputArgs, r.Runtime)
+ }
+ if err != nil {
+ return ok, failures, err
+ }
+
+ pool := shared.NewPool("pause", maxWorkers, len(ctrs))
+ for _, c := range ctrs {
+ ctr := c
+ pool.Add(shared.Job{
+ ID: ctr.ID(),
+ Fn: func() error {
+ err := ctr.Pause()
+ if err != nil {
+ logrus.Debugf("Failed to pause container %s: %s", ctr.ID(), err.Error())
+ }
+ return err
+ },
+ })
+ }
+ return pool.Run()
+}
+
+// UnpauseContainers removes container(s) based on CLI inputs.
+func (r *LocalRuntime) UnpauseContainers(ctx context.Context, cli *cliconfig.UnpauseValues) ([]string, map[string]error, error) {
+ var (
+ ok = []string{}
+ failures = map[string]error{}
+ ctrs []*libpod.Container
+ err error
+ )
+
+ maxWorkers := shared.DefaultPoolSize("pause")
+ if cli.GlobalIsSet("max-workers") {
+ maxWorkers = cli.GlobalFlags.MaxWorks
+ }
+ logrus.Debugf("Setting maximum rm workers to %d", maxWorkers)
+
+ if cli.All {
+ var filterFuncs []libpod.ContainerFilter
+ filterFuncs = append(filterFuncs, func(c *libpod.Container) bool {
+ state, _ := c.State()
+ return state == libpod.ContainerStatePaused
+ })
+ ctrs, err = r.GetContainers(filterFuncs...)
+ } else {
+ ctrs, err = shortcuts.GetContainersByContext(false, false, cli.InputArgs, r.Runtime)
+ }
+ if err != nil {
+ return ok, failures, err
+ }
+
+ pool := shared.NewPool("pause", maxWorkers, len(ctrs))
+ for _, c := range ctrs {
+ ctr := c
+ pool.Add(shared.Job{
+ ID: ctr.ID(),
+ Fn: func() error {
+ err := ctr.Unpause()
+ if err != nil {
+ logrus.Debugf("Failed to unpause container %s: %s", ctr.ID(), err.Error())
+ }
+ return err
+ },
+ })
+ }
+ return pool.Run()
+}