summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/utils/containers.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api/handlers/utils/containers.go')
-rw-r--r--pkg/api/handlers/utils/containers.go33
1 files changed, 21 insertions, 12 deletions
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go
index 1439a3a75..fac237f87 100644
--- a/pkg/api/handlers/utils/containers.go
+++ b/pkg/api/handlers/utils/containers.go
@@ -6,6 +6,8 @@ import (
"github.com/containers/podman/v2/libpod"
"github.com/containers/podman/v2/libpod/define"
+ "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v2/pkg/domain/infra/abi"
"github.com/gorilla/schema"
"github.com/pkg/errors"
)
@@ -16,10 +18,13 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
interval time.Duration
)
runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ // Now use the ABI implementation to prevent us from having duplicate
+ // code.
+ containerEngine := abi.ContainerEngine{Libpod: runtime}
decoder := r.Context().Value("decoder").(*schema.Decoder)
query := struct {
- Interval string `schema:"interval"`
- Condition string `schema:"condition"`
+ Interval string `schema:"interval"`
+ Condition define.ContainerStatus `schema:"condition"`
}{
// Override golang default values for types
}
@@ -27,6 +32,10 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return 0, err
}
+ options := entities.WaitOptions{
+ Condition: define.ContainerStateStopped,
+ }
+ name := GetName(r)
if _, found := r.URL.Query()["interval"]; found {
interval, err = time.ParseDuration(query.Interval)
if err != nil {
@@ -40,19 +49,19 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
return 0, err
}
}
- condition := define.ContainerStateStopped
+ options.Interval = interval
+
if _, found := r.URL.Query()["condition"]; found {
- condition, err = define.StringToContainerStatus(query.Condition)
- if err != nil {
- InternalServerError(w, err)
- return 0, err
- }
+ options.Condition = query.Condition
}
- name := GetName(r)
- con, err := runtime.LookupContainer(name)
+
+ report, err := containerEngine.ContainerWait(r.Context(), []string{name}, options)
if err != nil {
- ContainerNotFound(w, name, err)
return 0, err
}
- return con.WaitForConditionWithInterval(interval, condition)
+ if len(report) == 0 {
+ InternalServerError(w, errors.New("No reports returned"))
+ return 0, err
+ }
+ return report[0].ExitCode, report[0].Error
}