summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat
diff options
context:
space:
mode:
authorKorhonen Sami (Samlink) <k847259@ubuntu.saminet.fi>2020-07-03 13:00:21 +0300
committerKorhonen Sami (Samlink) <k847259@ubuntu.saminet.fi>2020-07-03 17:20:59 +0300
commite5bf56a48dca83d1f9daccfc271dc8093c91c497 (patch)
treeed89778e255261d7d9bd319d5ba0b89cb84a6e8d /pkg/api/handlers/compat
parentc131567401bea2867d597d79cce75b99012e64fb (diff)
downloadpodman-e5bf56a48dca83d1f9daccfc271dc8093c91c497.tar.gz
podman-e5bf56a48dca83d1f9daccfc271dc8093c91c497.tar.bz2
podman-e5bf56a48dca83d1f9daccfc271dc8093c91c497.zip
Fix issue #6803 Container inspect endpoint returns null for NetworkSettings/Ports
Implement mapping for NetworkSettings/Ports for Container inspect endpoint Signed-off-by: Sami Korhonen <skorhone@gmail.com>
Diffstat (limited to 'pkg/api/handlers/compat')
-rw-r--r--pkg/api/handlers/compat/containers.go29
1 files changed, 21 insertions, 8 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go
index b103e399d..5c76ab4f5 100644
--- a/pkg/api/handlers/compat/containers.go
+++ b/pkg/api/handlers/compat/containers.go
@@ -321,17 +321,17 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*types.ContainerJSON,
stopTimeout := int(l.StopTimeout())
- ports := make(nat.PortSet)
- for p := range inspect.HostConfig.PortBindings {
- splitp := strings.SplitN(p, "/", 2)
+ exposedPorts := make(nat.PortSet)
+ for ep := range inspect.HostConfig.PortBindings {
+ splitp := strings.SplitN(ep, "/", 2)
if len(splitp) != 2 {
- return nil, errors.Errorf("PORT/PROTOCOL Format required for %q", p)
+ return nil, errors.Errorf("PORT/PROTOCOL Format required for %q", ep)
}
- port, err := nat.NewPort(splitp[1], splitp[0])
+ exposedPort, err := nat.NewPort(splitp[1], splitp[0])
if err != nil {
return nil, err
}
- ports[port] = struct{}{}
+ exposedPorts[exposedPort] = struct{}{}
}
config := container.Config{
@@ -341,7 +341,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*types.ContainerJSON,
AttachStdin: inspect.Config.AttachStdin,
AttachStdout: inspect.Config.AttachStdout,
AttachStderr: inspect.Config.AttachStderr,
- ExposedPorts: ports,
+ ExposedPorts: exposedPorts,
Tty: inspect.Config.Tty,
OpenStdin: inspect.Config.OpenStdin,
StdinOnce: inspect.Config.StdinOnce,
@@ -371,6 +371,15 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*types.ContainerJSON,
return nil, err
}
+ p, err := json.Marshal(inspect.NetworkSettings.Ports)
+ if err != nil {
+ return nil, err
+ }
+ ports := nat.PortMap{}
+ if err := json.Unmarshal(p, &ports); err != nil {
+ return nil, err
+ }
+
networkSettingsDefault := types.DefaultNetworkSettings{
EndpointID: "",
Gateway: "",
@@ -382,8 +391,12 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*types.ContainerJSON,
MacAddress: l.Config().StaticMAC.String(),
}
+ networkSettingsBase := types.NetworkSettingsBase{
+ Ports: ports,
+ }
+
networkSettings := types.NetworkSettings{
- NetworkSettingsBase: types.NetworkSettingsBase{},
+ NetworkSettingsBase: networkSettingsBase,
DefaultNetworkSettings: networkSettingsDefault,
Networks: nil,
}