summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/utils
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-02-27 10:59:53 -0600
committerBrent Baude <bbaude@redhat.com>2020-02-28 09:36:53 -0600
commit09048731000e73b44a0243a0339d8c122eb8a165 (patch)
treedb939805cbb41f4ddd2db610256ba2186a8367db /pkg/api/handlers/utils
parentbaf27fa25eed668b5a73a1d7d4fe16214f1c260f (diff)
downloadpodman-09048731000e73b44a0243a0339d8c122eb8a165.tar.gz
podman-09048731000e73b44a0243a0339d8c122eb8a165.tar.bz2
podman-09048731000e73b44a0243a0339d8c122eb8a165.zip
rework apiv2 wait endpoint|binding
added the ability to wait on a condition (stopped, running, paused...) for a container. if a condition is not provided, wait will default to the stopped condition which uses the original wait code paths. if the condition is stopped, the container exit code will be returned. also, correct a mux issue we discovered. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/api/handlers/utils')
-rw-r--r--pkg/api/handlers/utils/containers.go38
-rw-r--r--pkg/api/handlers/utils/images.go3
2 files changed, 26 insertions, 15 deletions
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go
index 402005581..07efef0f5 100644
--- a/pkg/api/handlers/utils/containers.go
+++ b/pkg/api/handlers/utils/containers.go
@@ -78,9 +78,12 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request, force, vols bool) {
}
func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
+ var (
+ err error
+ interval time.Duration
+ )
runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder)
- // /{version}/containers/(name)/restart
query := struct {
Interval string `schema:"interval"`
Condition string `schema:"condition"`
@@ -91,25 +94,34 @@ 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
}
-
- if len(query.Condition) > 0 {
- UnSupportedParameter("condition")
+ if _, found := r.URL.Query()["interval"]; found {
+ interval, err = time.ParseDuration(query.Interval)
+ if err != nil {
+ InternalServerError(w, err)
+ return 0, err
+ }
+ } else {
+ interval, err = time.ParseDuration("250ms")
+ if err != nil {
+ InternalServerError(w, err)
+ return 0, err
+ }
+ }
+ condition := define.ContainerStateStopped
+ if _, found := r.URL.Query()["condition"]; found {
+ condition, err = define.StringToContainerStatus(query.Condition)
+ if err != nil {
+ InternalServerError(w, err)
+ return 0, err
+ }
}
-
name := GetName(r)
con, err := runtime.LookupContainer(name)
if err != nil {
ContainerNotFound(w, name, err)
return 0, err
}
- if len(query.Interval) > 0 {
- d, err := time.ParseDuration(query.Interval)
- if err != nil {
- Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse %s for interval", query.Interval))
- }
- return con.WaitWithInterval(d)
- }
- return con.Wait()
+ return con.WaitForConditionWithInterval(interval, condition)
}
// GenerateFilterFuncsFromMap is used to generate un-executed functions that can be used to filter
diff --git a/pkg/api/handlers/utils/images.go b/pkg/api/handlers/utils/images.go
index f68a71561..a97fd5c07 100644
--- a/pkg/api/handlers/utils/images.go
+++ b/pkg/api/handlers/utils/images.go
@@ -6,7 +6,6 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/image"
- "github.com/gorilla/mux"
"github.com/gorilla/schema"
)
@@ -28,7 +27,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) ([]*image.Image, error) {
return nil, err
}
var filters = []string{}
- if _, found := mux.Vars(r)["digests"]; found && query.Digests {
+ if _, found := r.URL.Query()["digests"]; found && query.Digests {
UnSupportedParameter("digests")
}