summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2019-03-04 17:21:23 -0700
committerJhon Honce <jhonce@redhat.com>2019-03-06 10:32:01 -0700
commit8a6758d5fdaba9e6ec58eeb23ee5123762c18b72 (patch)
tree4273a61b912797dc6cb4d27fb6743c5367a1dfa8 /cmd
parentc6c0b54c361df623378706ca5e41faac309ab7ac (diff)
downloadpodman-8a6758d5fdaba9e6ec58eeb23ee5123762c18b72.tar.gz
podman-8a6758d5fdaba9e6ec58eeb23ee5123762c18b72.tar.bz2
podman-8a6758d5fdaba9e6ec58eeb23ee5123762c18b72.zip
Implement podman-remote wait command and container subcommand
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/commands.go1
-rw-r--r--cmd/podman/main.go1
-rw-r--r--cmd/podman/varlink/io.podman.varlink8
-rw-r--r--cmd/podman/wait.go53
4 files changed, 28 insertions, 35 deletions
diff --git a/cmd/podman/commands.go b/cmd/podman/commands.go
index 150413970..c59db024b 100644
--- a/cmd/podman/commands.go
+++ b/cmd/podman/commands.go
@@ -35,7 +35,6 @@ func getMainCommands() []*cobra.Command {
_topCommand,
_umountCommand,
_unpauseCommand,
- _waitCommand,
}
if len(_varlinkCommand.Use) > 0 {
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index b3faf05c0..97ffa8930 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -52,6 +52,7 @@ var mainCommands = []*cobra.Command{
_stopCommand,
_tagCommand,
_versionCommand,
+ _waitCommand,
imageCommand.Command,
systemCommand.Command,
}
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index 73e6c15f9..296b20ed1 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -617,10 +617,10 @@ method UnpauseContainer(name: string) -> (container: string)
# ~~~
method GetAttachSockets(name: string) -> (sockets: Sockets)
-# WaitContainer takes the name or ID of a container and waits until the container stops. Upon stopping, the return
-# code of the container is returned. If the container container cannot be found by ID or name,
-# a [ContainerNotFound](#ContainerNotFound) error is returned.
-method WaitContainer(name: string) -> (exitcode: int)
+# WaitContainer takes the name or ID of a container and waits the given interval in milliseconds until the container
+# stops. Upon stopping, the return code of the container is returned. If the container container cannot be found by ID
+# or name, a [ContainerNotFound](#ContainerNotFound) error is returned.
+method WaitContainer(name: string, interval: int) -> (exitcode: int)
# RemoveContainer requires the name or ID of container as well a boolean representing whether a running container can be stopped and removed, and a boolean
# indicating whether to remove builtin volumes. Upon successful removal of the
diff --git a/cmd/podman/wait.go b/cmd/podman/wait.go
index 9df2e3208..6c2a8c9ff 100644
--- a/cmd/podman/wait.go
+++ b/cmd/podman/wait.go
@@ -2,11 +2,11 @@ package main
import (
"fmt"
- "os"
+ "reflect"
"time"
"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/spf13/cobra"
)
@@ -49,43 +49,36 @@ func waitCmd(c *cliconfig.WaitValues) error {
return errors.Errorf("you must provide at least one container name or id")
}
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ if c.Interval == 0 {
+ return errors.Errorf("interval must be greater then 0")
+ }
+ interval := time.Duration(c.Interval) * time.Millisecond
+
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
- return errors.Wrapf(err, "error creating libpod runtime")
+ return errors.Wrapf(err, "error creating runtime")
}
defer runtime.Shutdown(false)
+ ok, failures, err := runtime.WaitOnContainers(getContext(), c, interval)
if err != nil {
- return errors.Wrapf(err, "could not get config")
+ return err
}
- var lastError error
- if c.Latest {
- latestCtr, err := runtime.GetLatestContainer()
- if err != nil {
- return errors.Wrapf(err, "unable to wait on latest container")
- }
- args = append(args, latestCtr.ID())
+ for _, id := range ok {
+ fmt.Println(id)
}
- for _, container := range args {
- ctr, err := runtime.LookupContainer(container)
- if err != nil {
- return errors.Wrapf(err, "unable to find container %s", container)
- }
- if c.Interval == 0 {
- return errors.Errorf("interval must be greater then 0")
- }
- returnCode, err := ctr.WaitWithInterval(time.Duration(c.Interval) * time.Millisecond)
- if err != nil {
- if lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = errors.Wrapf(err, "failed to wait for the container %v", container)
- } else {
- fmt.Println(returnCode)
+ if len(failures) > 0 {
+ keys := reflect.ValueOf(failures).MapKeys()
+ lastKey := keys[len(keys)-1].String()
+ lastErr := failures[lastKey]
+ delete(failures, lastKey)
+
+ for _, err := range failures {
+ outputError(err)
}
+ return lastErr
}
-
- return lastError
+ return nil
}