mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Merge pull request #6729 from QiWang19/inspect-format
Reformat inspect network settings
This commit is contained in:
@ -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.
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user