Skip to content

Commit

Permalink
Merge pull request #9581 from baude/issue9529
Browse files Browse the repository at this point in the history
Add network summary to compat ps
  • Loading branch information
openshift-merge-robot authored Mar 3, 2021
2 parents 259bb5f + 8f21929 commit 8a1955f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/api/handlers/compat/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
Type: portMapping.Protocol,
}
}
inspect, err := l.Inspect(false)
if err != nil {
return nil, err
}

n, err := json.Marshal(inspect.NetworkSettings)
if err != nil {
return nil, err
}
networkSettings := types.SummaryNetworkSettings{}
if err := json.Unmarshal(n, &networkSettings); err != nil {
return nil, err
}

return &handlers.Container{Container: types.Container{
ID: l.ID(),
Expand All @@ -339,7 +352,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
NetworkMode string `json:",omitempty"`
}{
"host"},
NetworkSettings: nil,
NetworkSettings: &networkSettings,
Mounts: nil,
},
ContainerCreateConfig: types.ContainerCreateConfig{},
Expand Down
7 changes: 7 additions & 0 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ t GET libpod/containers/json?all=true 200 \
.[0].ExitCode=0 \
.[0].IsInfra=false

# Test compat API for Network Settings
t GET /containers/json?all=true 200 \
length=1 \
.[0].Id~[0-9a-f]\\{64\\} \
.[0].Image=$IMAGE \
.[0].NetworkSettings.Networks.podman.NetworkID=podman

# Make sure `limit` works.
t GET libpod/containers/json?limit=1 200 \
length=1 \
Expand Down

0 comments on commit 8a1955f

Please sign in to comment.