summaryrefslogtreecommitdiff
path: root/libpod/networking.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-01-05 15:15:52 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-01-08 13:54:32 +0000
commite2675ef921e6acb0131ddb5d81fe2d022ba8e022 (patch)
treea6187ac955650d5d766197771285927d1cbde1eb /libpod/networking.go
parent09d12d9be669567a0217eb3972089631457a834d (diff)
downloadpodman-e2675ef921e6acb0131ddb5d81fe2d022ba8e022.tar.gz
podman-e2675ef921e6acb0131ddb5d81fe2d022ba8e022.tar.bz2
podman-e2675ef921e6acb0131ddb5d81fe2d022ba8e022.zip
Add function to get IP address of a running container
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #192 Approved by: rhatdan
Diffstat (limited to 'libpod/networking.go')
-rw-r--r--libpod/networking.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/libpod/networking.go b/libpod/networking.go
index 3819d803d..966b40238 100644
--- a/libpod/networking.go
+++ b/libpod/networking.go
@@ -113,6 +113,27 @@ func joinNetNS(path string) (ns.NetNS, error) {
return ns, nil
}
+// Get a container's IP address
+func (r *Runtime) getContainerIP(ctr *Container) (net.IP, error) {
+ if ctr.state.NetNS == nil {
+ return nil, errors.Wrapf(ErrInvalidArg, "container %s has no network namespace, cannot get IP", ctr.ID())
+ }
+
+ podNetwork := getPodNetwork(ctr.ID(), ctr.Name(), ctr.state.NetNS.Path(), ctr.config.PortMappings)
+
+ ipStr, err := r.netPlugin.GetPodNetworkStatus(podNetwork)
+ if err != nil {
+ return nil, errors.Wrapf(err, "error retrieving network status of container %s", ctr.ID())
+ }
+
+ ip := net.ParseIP(ipStr)
+ if ip == nil {
+ return nil, errors.Wrapf(ErrInternal, "error parsing IP address %s for container %s", ipStr, ctr.ID())
+ }
+
+ return ip, nil
+}
+
// Tear down a network namespace
func (r *Runtime) teardownNetNS(ctr *Container) error {
if ctr.state.NetNS == nil {