summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api/handlers/libpod')
-rw-r--r--pkg/api/handlers/libpod/containers.go17
-rw-r--r--pkg/api/handlers/libpod/containers_create.go29
-rw-r--r--pkg/api/handlers/libpod/images.go41
-rw-r--r--pkg/api/handlers/libpod/pods.go9
4 files changed, 70 insertions, 26 deletions
diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go
index e11e26510..752b004d8 100644
--- a/pkg/api/handlers/libpod/containers.go
+++ b/pkg/api/handlers/libpod/containers.go
@@ -83,6 +83,8 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
Pod: query.Pod,
Sync: query.Sync,
}
+
+ all := query.All
if len(query.Filters) > 0 {
for k, v := range query.Filters {
for _, val := range v {
@@ -96,8 +98,12 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
}
}
- if !query.All {
- // The default is get only running containers. Do this with a filterfunc
+ // Docker thinks that if status is given as an input, then we should override
+ // the all setting and always deal with all containers.
+ if len(query.Filters["status"]) > 0 {
+ all = true
+ }
+ if !all {
runningOnly, err := shared.GenerateContainerFilterFuncs("status", define.ContainerStateRunning.String(), runtime)
if err != nil {
utils.InternalServerError(w, err)
@@ -178,13 +184,6 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) {
utils.WriteResponse(w, http.StatusOK, strconv.Itoa(int(exitCode)))
}
-func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
- // follow
- // since
- // timestamps
- // tail string
-}
-
func UnmountContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := utils.GetName(r)
diff --git a/pkg/api/handlers/libpod/containers_create.go b/pkg/api/handlers/libpod/containers_create.go
new file mode 100644
index 000000000..ebca41151
--- /dev/null
+++ b/pkg/api/handlers/libpod/containers_create.go
@@ -0,0 +1,29 @@
+package libpod
+
+import (
+ "encoding/json"
+ "net/http"
+
+ "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/api/handlers/utils"
+ "github.com/containers/libpod/pkg/specgen"
+ "github.com/pkg/errors"
+)
+
+// CreateContainer takes a specgenerator and makes a container. It returns
+// the new container ID on success along with any warnings.
+func CreateContainer(w http.ResponseWriter, r *http.Request) {
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ var sg specgen.SpecGenerator
+ if err := json.NewDecoder(r.Body).Decode(&sg); err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ return
+ }
+ ctr, err := sg.MakeContainer(runtime)
+ if err != nil {
+ utils.InternalServerError(w, err)
+ return
+ }
+ response := utils.ContainerCreateResponse{ID: ctr.ID()}
+ utils.WriteJSON(w, http.StatusCreated, response)
+}
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go
index bcbe4977e..eac0e4dad 100644
--- a/pkg/api/handlers/libpod/images.go
+++ b/pkg/api/handlers/libpod/images.go
@@ -46,17 +46,34 @@ func ImageExists(w http.ResponseWriter, r *http.Request) {
}
func ImageTree(w http.ResponseWriter, r *http.Request) {
- // tree is a bit of a mess ... logic is in adapter and therefore not callable from here. needs rework
-
- // name := utils.GetName(r)
- // _, layerInfoMap, _, err := s.Runtime.Tree(name)
- // if err != nil {
- // Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "Failed to find image information for %q", name))
- // return
- // }
- // it is not clear to me how to deal with this given all the processing of the image
- // is in main. we need to discuss how that really should be and return something useful.
- handlers.UnsupportedHandler(w, r)
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ name := utils.GetName(r)
+
+ img, err := runtime.ImageRuntime().NewFromLocal(name)
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(err, "Failed to find image %s", name))
+ return
+ }
+
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+ query := struct {
+ WhatRequires bool `schema:"whatrequires"`
+ }{
+ WhatRequires: false,
+ }
+ if err := decoder.Decode(&query, r.URL.Query()); err != nil {
+ utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
+ errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ return
+ }
+
+ tree, err := img.GenerateTree(query.WhatRequires)
+ if err != nil {
+ utils.Error(w, "Server error", http.StatusInternalServerError, errors.Wrapf(err, "failed to generate image tree for %s", name))
+ return
+ }
+
+ utils.WriteResponse(w, http.StatusOK, tree)
}
func GetImage(w http.ResponseWriter, r *http.Request) {
@@ -72,8 +89,8 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
return
}
utils.WriteResponse(w, http.StatusOK, inspect)
-
}
+
func GetImages(w http.ResponseWriter, r *http.Request) {
images, err := utils.GetImages(w, r)
if err != nil {
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go
index e9297d91b..f5700579b 100644
--- a/pkg/api/handlers/libpod/pods.go
+++ b/pkg/api/handlers/libpod/pods.go
@@ -42,7 +42,8 @@ func PodCreate(w http.ResponseWriter, r *http.Request) {
}
if len(input.Labels) > 0 {
- if err := parse.ReadKVStrings(labels, []string{}, input.Labels); err != nil {
+ labels, err = parse.GetAllLabels([]string{}, input.Labels)
+ if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}
@@ -98,12 +99,10 @@ func PodCreate(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http_code, err)
return
}
- utils.WriteResponse(w, http.StatusCreated, handlers.IDResponse{ID: pod.CgroupParent()})
+ utils.WriteResponse(w, http.StatusCreated, handlers.IDResponse{ID: pod.ID()})
}
func Pods(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 500 internal
var (
runtime = r.Context().Value("runtime").(*libpod.Runtime)
podInspectData []*libpod.PodInspect
@@ -120,7 +119,7 @@ func Pods(w http.ResponseWriter, r *http.Request) {
return
}
- if _, found := r.URL.Query()["filters"]; found {
+ if len(query.Filters) > 0 {
utils.Error(w, "filters are not implemented yet", http.StatusInternalServerError, define.ErrNotImplemented)
return
}