summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-03-06 21:19:55 +0100
committerGitHub <noreply@github.com>2020-03-06 21:19:55 +0100
commitc3177b781b69b45e2a084b83d44c39abd8e94132 (patch)
treec0dfa81e817ce65ebfea730f7bc25bfb87543497 /pkg/api/handlers
parent6365fab22bc519c6c16573e8407088215b42d435 (diff)
parent06f5664e9dc335e3cfc42475e8f807036312a801 (diff)
downloadpodman-c3177b781b69b45e2a084b83d44c39abd8e94132.tar.gz
podman-c3177b781b69b45e2a084b83d44c39abd8e94132.tar.bz2
podman-c3177b781b69b45e2a084b83d44c39abd8e94132.zip
Merge pull request #5410 from st1971/api-fixes
APIv2: compatible api fixes
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/generic/containers.go16
-rw-r--r--pkg/api/handlers/generic/images.go2
-rw-r--r--pkg/api/handlers/types.go23
3 files changed, 30 insertions, 11 deletions
diff --git a/pkg/api/handlers/generic/containers.go b/pkg/api/handlers/generic/containers.go
index ab587ded4..b8460702c 100644
--- a/pkg/api/handlers/generic/containers.go
+++ b/pkg/api/handlers/generic/containers.go
@@ -57,6 +57,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
}{
// 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
@@ -85,7 +86,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
var list = make([]*handlers.Container, len(containers))
for i, ctnr := range containers {
- api, err := handlers.LibpodToContainer(ctnr, infoData)
+ api, err := handlers.LibpodToContainer(ctnr, infoData, query.Size)
if err != nil {
utils.InternalServerError(w, err)
return
@@ -97,6 +98,17 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
func GetContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+ query := struct {
+ Size bool `schema:"size"`
+ }{
+ // 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
+ }
name := utils.GetName(r)
ctnr, err := runtime.LookupContainer(name)
@@ -104,7 +116,7 @@ func GetContainer(w http.ResponseWriter, r *http.Request) {
utils.ContainerNotFound(w, name, err)
return
}
- api, err := handlers.LibpodToContainerJSON(ctnr)
+ api, err := handlers.LibpodToContainerJSON(ctnr, query.Size)
if err != nil {
utils.InternalServerError(w, err)
return
diff --git a/pkg/api/handlers/generic/images.go b/pkg/api/handlers/generic/images.go
index 1ced499d9..3da5807ec 100644
--- a/pkg/api/handlers/generic/images.go
+++ b/pkg/api/handlers/generic/images.go
@@ -305,7 +305,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Failed get images"))
return
}
- var summaries = make([]*handlers.ImageSummary, len(images)+1)
+ var summaries = make([]*handlers.ImageSummary, len(images))
for j, img := range images {
is, err := handlers.ImageToImageSummary(img)
if err != nil {
diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go
index 2930a9567..2e429dc58 100644
--- a/pkg/api/handlers/types.go
+++ b/pkg/api/handlers/types.go
@@ -347,7 +347,7 @@ func ImageDataToImageInspect(ctx context.Context, l *libpodImage.Image) (*ImageI
}
-func LibpodToContainer(l *libpod.Container, infoData []define.InfoData) (*Container, error) {
+func LibpodToContainer(l *libpod.Container, infoData []define.InfoData, sz bool) (*Container, error) {
imageId, imageName := l.Image()
var (
@@ -360,11 +360,18 @@ func LibpodToContainer(l *libpod.Container, infoData []define.InfoData) (*Contai
if state, err = l.State(); err != nil {
return nil, err
}
- if sizeRW, err = l.RWSize(); err != nil {
- return nil, err
+ stateStr := state.String()
+ if stateStr == "configured" {
+ stateStr = "created"
}
- if sizeRootFs, err = l.RootFsSize(); err != nil {
- return nil, err
+
+ if sz {
+ if sizeRW, err = l.RWSize(); err != nil {
+ return nil, err
+ }
+ if sizeRootFs, err = l.RootFsSize(); err != nil {
+ return nil, err
+ }
}
return &Container{docker.Container{
@@ -378,7 +385,7 @@ func LibpodToContainer(l *libpod.Container, infoData []define.InfoData) (*Contai
SizeRw: sizeRW,
SizeRootFs: sizeRootFs,
Labels: l.Labels(),
- State: string(state),
+ State: stateStr,
Status: "",
HostConfig: struct {
NetworkMode string `json:",omitempty"`
@@ -391,9 +398,9 @@ func LibpodToContainer(l *libpod.Container, infoData []define.InfoData) (*Contai
}, nil
}
-func LibpodToContainerJSON(l *libpod.Container) (*docker.ContainerJSON, error) {
+func LibpodToContainerJSON(l *libpod.Container, sz bool) (*docker.ContainerJSON, error) {
_, imageName := l.Image()
- inspect, err := l.Inspect(true)
+ inspect, err := l.Inspect(sz)
if err != nil {
return nil, err
}