github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/api/handlers/compat/system.go (about) 1 package compat 2 3 import ( 4 "net/http" 5 "strings" 6 7 "github.com/hanks177/podman/v4/libpod" 8 "github.com/hanks177/podman/v4/pkg/api/handlers" 9 "github.com/hanks177/podman/v4/pkg/api/handlers/utils" 10 api "github.com/hanks177/podman/v4/pkg/api/types" 11 "github.com/hanks177/podman/v4/pkg/domain/entities" 12 "github.com/hanks177/podman/v4/pkg/domain/infra/abi" 13 docker "github.com/docker/docker/api/types" 14 ) 15 16 func GetDiskUsage(w http.ResponseWriter, r *http.Request) { 17 options := entities.SystemDfOptions{} 18 runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) 19 ic := abi.ContainerEngine{Libpod: runtime} 20 df, err := ic.SystemDf(r.Context(), options) 21 if err != nil { 22 utils.InternalServerError(w, err) 23 return 24 } 25 26 imgs := make([]*docker.ImageSummary, len(df.Images)) 27 for i, o := range df.Images { 28 t := docker.ImageSummary{ 29 Containers: int64(o.Containers), 30 Created: o.Created.Unix(), 31 ID: o.ImageID, 32 Labels: map[string]string{}, 33 ParentID: "", 34 RepoDigests: nil, 35 RepoTags: []string{o.Tag}, 36 SharedSize: o.SharedSize, 37 Size: o.Size, 38 VirtualSize: o.Size - o.UniqueSize, 39 } 40 imgs[i] = &t 41 } 42 43 ctnrs := make([]*docker.Container, len(df.Containers)) 44 for i, o := range df.Containers { 45 t := docker.Container{ 46 ID: o.ContainerID, 47 Names: []string{o.Names}, 48 Image: o.Image, 49 ImageID: o.Image, 50 Command: strings.Join(o.Command, " "), 51 Created: o.Created.Unix(), 52 Ports: nil, 53 SizeRw: o.RWSize, 54 SizeRootFs: o.Size, 55 Labels: map[string]string{}, 56 State: o.Status, 57 Status: o.Status, 58 HostConfig: struct { 59 NetworkMode string `json:",omitempty"` 60 }{}, 61 NetworkSettings: nil, 62 Mounts: nil, 63 } 64 ctnrs[i] = &t 65 } 66 67 vols := make([]*docker.Volume, len(df.Volumes)) 68 for i, o := range df.Volumes { 69 t := docker.Volume{ 70 CreatedAt: "", 71 Driver: "", 72 Labels: map[string]string{}, 73 Mountpoint: "", 74 Name: o.VolumeName, 75 Options: nil, 76 Scope: "local", 77 Status: nil, 78 UsageData: &docker.VolumeUsageData{ 79 RefCount: 1, 80 Size: o.Size, 81 }, 82 } 83 vols[i] = &t 84 } 85 86 utils.WriteResponse(w, http.StatusOK, handlers.DiskUsage{DiskUsage: docker.DiskUsage{ 87 LayersSize: 0, 88 Images: imgs, 89 Containers: ctnrs, 90 Volumes: vols, 91 BuildCache: []*docker.BuildCache{}, 92 BuilderSize: 0, 93 }}) 94 }