diff options
author | Matthew Heon <mheon@redhat.com> | 2018-04-26 12:20:25 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-04-26 17:26:13 +0000 |
commit | 0ccfd7dc20c11bc2f9d646c98cc67fb399cd9013 (patch) | |
tree | 3e0e34a0254f9c11542463371f0510f0738b8fab /libpod | |
parent | 6ac8a24db4ab3e2bbc85feca2bee8cb1c868c7f6 (diff) | |
download | podman-0ccfd7dc20c11bc2f9d646c98cc67fb399cd9013.tar.gz podman-0ccfd7dc20c11bc2f9d646c98cc67fb399cd9013.tar.bz2 podman-0ccfd7dc20c11bc2f9d646c98cc67fb399cd9013.zip |
Retrieve IP addresses for container from DB
Instead of execing out to the host's IP, use the IP address we
got back from CNI to populate Inspect's IP address information.
Signed-off-by: Matthew Heon <mheon@redhat.com>
Closes: #680
Approved by: umohnani8
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_inspect.go | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index b3e8ebeb9..6b62a3f44 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -1,6 +1,8 @@ package libpod import ( + "strings" + "github.com/cri-o/ocicni/pkg/ocicni" "github.com/projectatomic/libpod/pkg/inspect" "github.com/sirupsen/logrus" @@ -92,7 +94,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *inspect.Data) Gateway: "", // TODO GlobalIPv6Addresses: []string{}, // TODO - do we even support IPv6? GlobalIPv6PrefixLen: 0, // TODO - do we even support IPv6? - IPAddress: "", + IPAddress: nil, IPPrefixLen: 0, // TODO IPv6Gateway: "", // TODO - do we even support IPv6? MacAddress: "", // TODO @@ -106,14 +108,19 @@ func (c *Container) getContainerInspectData(size bool, driverData *inspect.Data) // Get information on the container's network namespace (if present) if runtimeInfo.NetNS != nil { - // Get IP address - ip, err := c.runtime.getContainerIP(c) - if err != nil { - logrus.Errorf("error getting container %q IP: %v", config.ID, err) - } else { - data.NetworkSettings.IPAddress = ip.To4().String() + // Go through our IP addresses + ctrIPs := []string{} + + for _, ctrIP := range c.state.IPs { + if ctrIP.Version == "4" { + ipWithMask := ctrIP.Address.String() + splitIP := strings.Split(ipWithMask, "/") + ctrIPs = append(ctrIPs, splitIP[0]) + } } + data.NetworkSettings.IPAddress = ctrIPs + // Set network namespace path data.NetworkSettings.SandboxKey = runtimeInfo.NetNS.Path() } |