summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/generic
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-01-21 12:44:50 -0600
committerBrent Baude <bbaude@redhat.com>2020-01-23 11:58:26 -0600
commitcf7be58b2c160e2e1df737015c913fc1aff1dbe8 (patch)
tree46b7b75d80fc22fc69e6f3ddb1f4dec1c931ef35 /pkg/api/handlers/generic
parente6cf0ec857fdda82479f630defd0c9f738e9aab4 (diff)
downloadpodman-cf7be58b2c160e2e1df737015c913fc1aff1dbe8.tar.gz
podman-cf7be58b2c160e2e1df737015c913fc1aff1dbe8.tar.bz2
podman-cf7be58b2c160e2e1df737015c913fc1aff1dbe8.zip
Review corrections pass #2
Add API review comments to correct documentation and endpoints. Also, add a libpode prune method to reduce code duplication. Only used right now for the API but when the remote client is wired, we will switch over there too. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/api/handlers/generic')
-rw-r--r--pkg/api/handlers/generic/containers.go80
-rw-r--r--pkg/api/handlers/generic/containers_create.go4
2 files changed, 32 insertions, 52 deletions
diff --git a/pkg/api/handlers/generic/containers.go b/pkg/api/handlers/generic/containers.go
index 5a0a51fd7..8dc73ae14 100644
--- a/pkg/api/handlers/generic/containers.go
+++ b/pkg/api/handlers/generic/containers.go
@@ -1,7 +1,6 @@
package generic
import (
- "context"
"encoding/binary"
"fmt"
"net/http"
@@ -11,12 +10,10 @@ import (
"time"
"github.com/containers/libpod/libpod"
- "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/logs"
"github.com/containers/libpod/pkg/api/handlers"
"github.com/containers/libpod/pkg/api/handlers/utils"
"github.com/containers/libpod/pkg/util"
- "github.com/docker/docker/api/types"
"github.com/gorilla/mux"
"github.com/gorilla/schema"
"github.com/pkg/errors"
@@ -47,14 +44,40 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) {
}
func ListContainers(w http.ResponseWriter, r *http.Request) {
+ var (
+ containers []*libpod.Container
+ err error
+ )
runtime := r.Context().Value("runtime").(*libpod.Runtime)
-
- containers, err := runtime.GetAllContainers()
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+ query := struct {
+ All bool `schema:"all"`
+ Limit int `schema:"limit"`
+ Size bool `schema:"size"`
+ Filters map[string][]string `schema:"filters"`
+ }{
+ // override any golang type defaults
+ }
+ if err := decoder.Decode(&query, r.URL.Query()); err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
+ return
+ }
+ if query.All {
+ containers, err = runtime.GetAllContainers()
+ } else {
+ containers, err = runtime.GetRunningContainers()
+ }
if err != nil {
utils.InternalServerError(w, err)
return
}
-
+ if _, found := mux.Vars(r)["limit"]; found {
+ last := query.Limit
+ if len(containers) > last {
+ containers = containers[len(containers)-last:]
+ }
+ }
+ // TODO filters still need to be applied
infoData, err := runtime.Info()
if err != nil {
utils.InternalServerError(w, errors.Wrapf(err, "Failed to obtain system info"))
@@ -125,51 +148,6 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) {
})
}
-func PruneContainers(w http.ResponseWriter, r *http.Request) {
- runtime := r.Context().Value("runtime").(*libpod.Runtime)
-
- containers, err := runtime.GetAllContainers()
- if err != nil {
- utils.InternalServerError(w, err)
- return
- }
-
- deletedContainers := []string{}
- var spaceReclaimed uint64
- for _, ctnr := range containers {
- // Only remove stopped or exit'ed containers.
- state, err := ctnr.State()
- if err != nil {
- utils.InternalServerError(w, err)
- return
- }
- switch state {
- case define.ContainerStateStopped, define.ContainerStateExited:
- default:
- continue
- }
-
- deletedContainers = append(deletedContainers, ctnr.ID())
- cSize, err := ctnr.RootFsSize()
- if err != nil {
- utils.InternalServerError(w, err)
- return
- }
- spaceReclaimed += uint64(cSize)
-
- err = runtime.RemoveContainer(context.Background(), ctnr, false, false)
- if err != nil && !(errors.Cause(err) == define.ErrCtrRemoved) {
- utils.InternalServerError(w, err)
- return
- }
- }
- report := types.ContainersPruneReport{
- ContainersDeleted: deletedContainers,
- SpaceReclaimed: spaceReclaimed,
- }
- utils.WriteResponse(w, http.StatusOK, report)
-}
-
func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
decoder := r.Context().Value("decoder").(*schema.Decoder)
runtime := r.Context().Value("runtime").(*libpod.Runtime)
diff --git a/pkg/api/handlers/generic/containers_create.go b/pkg/api/handlers/generic/containers_create.go
index f98872690..edefd5757 100644
--- a/pkg/api/handlers/generic/containers_create.go
+++ b/pkg/api/handlers/generic/containers_create.go
@@ -40,7 +40,9 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
return
}
-
+ if len(input.HostConfig.Links) > 0 {
+ utils.Error(w, utils.ErrLinkNotSupport.Error(), http.StatusBadRequest, errors.Wrapf(utils.ErrLinkNotSupport, "bad parameter"))
+ }
newImage, err := runtime.ImageRuntime().NewFromLocal(input.Image)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "NewFromLocal()"))