From c31a5c0d9c9db52f03caa443a3fdfdce194046e8 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 1 Dec 2020 22:12:16 +0100 Subject: Add support for network ids The network ID is not stored. It is just the sha256 hash from the network name. There is a risk of a potential hash collision. However it's very unlikely and even if we hit this it will complain that more than network with this ID exists. The main benefit is that the compat api can have proper network ID support. Also this adds the support for `podman network ls --format "{{.ID}}"` and `--filter id=`. It also ensures that we can do network rm and network inspect . Since we use a hash this commit is backwards compatible even for already existing networks. Signed-off-by: Paul Holzinger --- libpod/network/netconflist.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'libpod/network/netconflist.go') diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go index a5fec5e80..d61b96ecb 100644 --- a/libpod/network/netconflist.go +++ b/libpod/network/netconflist.go @@ -230,8 +230,16 @@ func IfPassesFilter(netconf *libcni.NetworkConfigList, filters map[string][]stri } } + case "id": + // matches part of one id + for _, filterValue := range filterValues { + if strings.Contains(GetNetworkID(netconf.Name), filterValue) { + result = true + break + } + } + // TODO: add dangling filter - // TODO TODO: add id filter if we support ids default: return false, errors.Errorf("invalid filter %q", key) -- cgit v1.2.3-54-g00ecf