summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authorSteve Taylor <steven@taylormuff.co.uk>2020-03-05 23:02:45 +0000
committerSteve Taylor <steven@taylormuff.co.uk>2020-03-05 23:02:45 +0000
commit83e52cf787eead5434a982230f0fdc8b4f3a10df (patch)
treea54a5348098aa069cd494c53f5b588f94c32e566 /pkg/api/handlers
parentda15f2f8817a432bce7e578de23554e5ed854f13 (diff)
downloadpodman-83e52cf787eead5434a982230f0fdc8b4f3a10df.tar.gz
podman-83e52cf787eead5434a982230f0fdc8b4f3a10df.tar.bz2
podman-83e52cf787eead5434a982230f0fdc8b4f3a10df.zip
Implemented size parameter on GetContainer
Signed-off-by: Steve Taylor <steven@taylormuff.co.uk>
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/generic/containers.go16
-rw-r--r--pkg/api/handlers/types.go23
2 files changed, 35 insertions, 4 deletions
diff --git a/pkg/api/handlers/generic/containers.go b/pkg/api/handlers/generic/containers.go
index 5b52cdfa9..24b0ecb77 100644
--- a/pkg/api/handlers/generic/containers.go
+++ b/pkg/api/handlers/generic/containers.go
@@ -101,6 +101,20 @@ 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
+ }
+
+ // Default Size to false
+ query.Size = false
+
+ 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)
@@ -108,7 +122,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/types.go b/pkg/api/handlers/types.go
index ada249e56..c5a5d1088 100644
--- a/pkg/api/handlers/types.go
+++ b/pkg/api/handlers/types.go
@@ -402,7 +402,12 @@ func LibpodToContainer(l *libpod.Container, infoData []define.InfoData, sz bool)
}, nil
}
-func LibpodToContainerJSON(l *libpod.Container) (*docker.ContainerJSON, error) {
+func LibpodToContainerJSON(l *libpod.Container, sz bool) (*docker.ContainerJSON, error) {
+ var (
+ sizeRootFs int64
+ sizeRW int64
+ )
+
_, imageName := l.Image()
inspect, err := l.Inspect(true)
if err != nil {
@@ -439,6 +444,18 @@ func LibpodToContainerJSON(l *libpod.Container) (*docker.ContainerJSON, error) {
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
+ }
+ } else {
+ sizeRW = 0
+ sizeRootFs = 0
+ }
+
cb := docker.ContainerJSONBase{
ID: l.ID(),
Created: l.CreatedTime().String(),
@@ -461,8 +478,8 @@ func LibpodToContainerJSON(l *libpod.Container) (*docker.ContainerJSON, error) {
ExecIDs: inspect.ExecIDs,
HostConfig: &hc,
GraphDriver: graphDriver,
- SizeRw: inspect.SizeRw,
- SizeRootFs: &inspect.SizeRootFs,
+ SizeRw: &sizeRW,
+ SizeRootFs: &sizeRootFs,
}
stopTimeout := int(l.StopTimeout())