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 /pkg/domain | |
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 'pkg/domain')
-rw-r--r-- | pkg/domain/filters/containers.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/pkg/domain/filters/containers.go b/pkg/domain/filters/containers.go index 965a12468..dc9fed2a4 100644 --- a/pkg/domain/filters/containers.go +++ b/pkg/domain/filters/containers.go @@ -211,6 +211,36 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo }, nil case "network": return func(c *libpod.Container) bool { + networkMode := c.NetworkMode() + // support docker like `--filter network=container:<IDorName>` + // check if networkMode is configured as `container:<ctr>` + // peform a match against filter `container:<IDorName>` + // networks is already going to be empty if `container:<ctr>` is configured as Mode + if strings.HasPrefix(networkMode, "container:") { + networkModeContainerPart := strings.SplitN(networkMode, ":", 2) + if len(networkModeContainerPart) < 2 { + return false + } + networkModeContainerID := networkModeContainerPart[1] + for _, val := range filterValues { + if strings.HasPrefix(val, "container:") { + filterNetworkModePart := strings.SplitN(val, ":", 2) + if len(filterNetworkModePart) < 2 { + return false + } + filterNetworkModeIDorName := filterNetworkModePart[1] + filterID, err := r.LookupContainerID(filterNetworkModeIDorName) + if err != nil { + return false + } + if filterID == networkModeContainerID { + return true + } + } + } + return false + } + networks, _, err := c.Networks() // if err or no networks, quick out if err != nil || len(networks) == 0 { |