summaryrefslogtreecommitdiff
path: root/cmd/podman/pod_stop.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pod_stop.go')
-rw-r--r--cmd/podman/pod_stop.go47
1 files changed, 15 insertions, 32 deletions
diff --git a/cmd/podman/pod_stop.go b/cmd/podman/pod_stop.go
index 52c92b521..62d0d4aa5 100644
--- a/cmd/podman/pod_stop.go
+++ b/cmd/podman/pod_stop.go
@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
+ "github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -47,43 +47,26 @@ func init() {
}
func podStopCmd(c *cliconfig.PodStopValues) error {
- timeout := -1
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- // getPodsFromContext returns an error when a requested pod
- // isn't found. The only fatal error scenerio is when there are no pods
- // in which case the following loop will be skipped.
- pods, lastError := getPodsFromContext(&c.PodmanCommand, runtime)
-
- ctx := getContext()
-
- if c.Flag("timeout").Changed {
- timeout = int(c.Timeout)
+ podStopIds, podStopErrors := runtime.StopPods(getContext(), c)
+ for _, p := range podStopIds {
+ fmt.Println(p)
}
- for _, pod := range pods {
- // set cleanup to true to clean mounts and namespaces
- ctr_errs, err := pod.StopWithTimeout(ctx, true, timeout)
- if ctr_errs != nil {
- for ctr, err := range ctr_errs {
- if lastError != nil {
- logrus.Errorf("%q", lastError)
- }
- lastError = errors.Wrapf(err, "unable to stop container %q on pod %q", ctr, pod.ID())
- }
- continue
- }
- if err != nil {
- if lastError != nil {
- logrus.Errorf("%q", lastError)
- }
- lastError = errors.Wrapf(err, "unable to stop pod %q", pod.ID())
- continue
- }
- fmt.Println(pod.ID())
+ if len(podStopErrors) == 0 {
+ return nil
+ }
+ // Grab the last error
+ lastError := podStopErrors[len(podStopErrors)-1]
+ // Remove the last error from the error slice
+ podStopErrors = podStopErrors[:len(podStopErrors)-1]
+
+ for _, err := range podStopErrors {
+ logrus.Errorf("%q", err)
}
return lastError
}