Skip to content

Commit

Permalink
Implemented size parameter on GetContainer
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Taylor <[email protected]>
  • Loading branch information
st1971 committed Mar 5, 2020
1 parent da15f2f commit 83e52cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
16 changes: 15 additions & 1 deletion pkg/api/handlers/generic/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,28 @@ 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)
if err != nil {
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
Expand Down
23 changes: 20 additions & 3 deletions pkg/api/handlers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand All @@ -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())
Expand Down

0 comments on commit 83e52cf

Please sign in to comment.