diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-01-05 15:15:52 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-08 13:54:32 +0000 |
commit | e2675ef921e6acb0131ddb5d81fe2d022ba8e022 (patch) | |
tree | a6187ac955650d5d766197771285927d1cbde1eb /libpod/container.go | |
parent | 09d12d9be669567a0217eb3972089631457a834d (diff) | |
download | podman-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/container.go')
-rw-r--r-- | libpod/container.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libpod/container.go b/libpod/container.go index efb4873b0..31f84ebb5 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "io/ioutil" + "net" "os" "path/filepath" "strconv" @@ -297,6 +298,23 @@ func (c *Container) LogPath() string { return c.logPath() } +// IPAddress returns the IP address of the container +// If the container does not have a network namespace, an error will be returned +func (c *Container) IPAddress() (net.IP, error) { + c.lock.Lock() + defer c.lock.Unlock() + + if err := c.syncContainer(); err != nil { + return nil, errors.Wrapf(err, "error updating container %s state", c.ID()) + } + + if !c.config.CreateNetNS || c.state.NetNS == nil { + return nil, errors.Wrapf(ErrInvalidArg, "container %s does not have a network namespace", c.ID()) + } + + return c.runtime.getContainerIP(c) +} + // ExitCode returns the exit code of the container as // an int32 func (c *Container) ExitCode() (int32, error) { |