diff options
author | flouthoc <flouthoc.git@gmail.com> | 2021-07-29 16:25:18 +0530 |
---|---|---|
committer | flouthoc <flouthoc.git@gmail.com> | 2021-07-30 19:31:05 +0530 |
commit | 2a484e782a23ad67c98e22121fde2b83b4072d1a (patch) | |
tree | 4691b5c19020ec9281bda7e58dee88e6d63d753f /libpod/container.go | |
parent | f17b810279fd04c3d574e8d3dcc1878d50083a68 (diff) | |
download | podman-2a484e782a23ad67c98e22121fde2b83b4072d1a.tar.gz podman-2a484e782a23ad67c98e22121fde2b83b4072d1a.tar.bz2 podman-2a484e782a23ad67c98e22121fde2b83b4072d1a.zip |
ps: support the container notation for ps --filter network=...
Signed-off-by: flouthoc <flouthoc.git@gmail.com>
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/libpod/container.go b/libpod/container.go index 4b9bea5fc..f3f4b27b7 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -1173,6 +1173,46 @@ func (c *Container) Networks() ([]string, bool, error) { return c.networks() } +// NetworkMode gets the configured network mode for the container. +// Get actual value from the database +func (c *Container) NetworkMode() string { + networkMode := "" + ctrSpec := c.config.Spec + + switch { + case c.config.CreateNetNS: + // We actually store the network + // mode for Slirp and Bridge, so + // we can just use that + networkMode = string(c.config.NetMode) + case c.config.NetNsCtr != "": + networkMode = fmt.Sprintf("container:%s", c.config.NetNsCtr) + default: + // Find the spec's network namespace. + // If there is none, it's host networking. + // If there is one and it has a path, it's "ns:". + foundNetNS := false + for _, ns := range ctrSpec.Linux.Namespaces { + if ns.Type == spec.NetworkNamespace { + foundNetNS = true + if ns.Path != "" { + networkMode = fmt.Sprintf("ns:%s", ns.Path) + } else { + // We're making a network ns, but not + // configuring with Slirp or CNI. That + // means it's --net=none + networkMode = "none" + } + break + } + } + if !foundNetNS { + networkMode = "host" + } + } + return networkMode +} + // Unlocked accessor for networks func (c *Container) networks() ([]string, bool, error) { networks, err := c.runtime.state.GetNetworks(c) |