aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorQi Wang <qiwan@redhat.com>2020-06-23 11:29:11 -0400
committerQi Wang <qiwan@redhat.com>2020-06-23 16:14:27 -0400
commitf586c006f8428a04fce5a5c7ae6b921e6337ebe6 (patch)
tree66aa9e658e7bd3efca34b66354b16a2a4ba0b20d /libpod
parent81f4204e4e0c8074e2709bd7c4db3f1f61d1b351 (diff)
downloadpodman-f586c006f8428a04fce5a5c7ae6b921e6337ebe6.tar.gz
podman-f586c006f8428a04fce5a5c7ae6b921e6337ebe6.tar.bz2
podman-f586c006f8428a04fce5a5c7ae6b921e6337ebe6.zip
Reformat inspect network settings
Reformat ports of inspect network settings to compatible with docker inspect. Close #5380 Signed-off-by: Qi Wang <qiwan@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/define/container_inspect.go15
-rw-r--r--libpod/networking_linux.go16
2 files changed, 20 insertions, 11 deletions
diff --git a/libpod/define/container_inspect.go b/libpod/define/container_inspect.go
index 27ada8706..3fbeb8f0b 100644
--- a/libpod/define/container_inspect.go
+++ b/libpod/define/container_inspect.go
@@ -5,7 +5,6 @@ import (
"github.com/containers/image/v5/manifest"
"github.com/containers/libpod/libpod/driver"
- "github.com/cri-o/ocicni/pkg/ocicni"
)
// InspectContainerConfig holds further data about how a container was initially
@@ -571,13 +570,13 @@ type InspectAdditionalNetwork struct {
type InspectNetworkSettings struct {
InspectBasicNetworkConfig
- Bridge string `json:"Bridge"`
- SandboxID string `json:"SandboxID"`
- HairpinMode bool `json:"HairpinMode"`
- LinkLocalIPv6Address string `json:"LinkLocalIPv6Address"`
- LinkLocalIPv6PrefixLen int `json:"LinkLocalIPv6PrefixLen"`
- Ports []ocicni.PortMapping `json:"Ports"`
- SandboxKey string `json:"SandboxKey"`
+ Bridge string `json:"Bridge"`
+ SandboxID string `json:"SandboxID"`
+ HairpinMode bool `json:"HairpinMode"`
+ LinkLocalIPv6Address string `json:"LinkLocalIPv6Address"`
+ LinkLocalIPv6PrefixLen int `json:"LinkLocalIPv6PrefixLen"`
+ Ports map[string][]InspectHostPort `json:"Ports"`
+ SandboxKey string `json:"SandboxKey"`
// Networks contains information on non-default CNI networks this
// container has joined.
// It is a map of network name to network information.
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 0c9d28701..f53573645 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -587,10 +587,20 @@ func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) {
// network.
func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, error) {
settings := new(define.InspectNetworkSettings)
- settings.Ports = []ocicni.PortMapping{}
+ settings.Ports = make(map[string][]define.InspectHostPort)
if c.config.PortMappings != nil {
- // TODO: This may not be safe.
- settings.Ports = c.config.PortMappings
+ for _, port := range c.config.PortMappings {
+ key := fmt.Sprintf("%d/%s", port.ContainerPort, port.Protocol)
+ mapping := settings.Ports[key]
+ if mapping == nil {
+ mapping = []define.InspectHostPort{}
+ }
+ mapping = append(mapping, define.InspectHostPort{
+ HostIP: port.HostIP,
+ HostPort: fmt.Sprintf("%d", port.HostPort),
+ })
+ settings.Ports[key] = mapping
+ }
}
// We can't do more if the network is down.