diff options
author | Paul Holzinger <paul.holzinger@web.de> | 2020-09-02 18:13:58 +0200 |
---|---|---|
committer | Paul Holzinger <paul.holzinger@web.de> | 2020-09-07 15:39:41 +0200 |
commit | 5b8f3f2f1f863dfb58e5d3cfda95e7ecb6582b22 (patch) | |
tree | a413ccdad49a09f2bae47dff5c549d12465ccb27 /pkg/api/handlers/compat | |
parent | 1184cdf03d8464451d36b24643e57b65a8b97980 (diff) | |
download | podman-5b8f3f2f1f863dfb58e5d3cfda95e7ecb6582b22.tar.gz podman-5b8f3f2f1f863dfb58e5d3cfda95e7ecb6582b22.tar.bz2 podman-5b8f3f2f1f863dfb58e5d3cfda95e7ecb6582b22.zip |
APIv2 Add network list filtering
Add the filter option to the libpod endpoint.
Add support for the name filter on the docker endpoint.
Add apiv2 tests for the network list endpoints.
Enable podman network integration tests for remote.
Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'pkg/api/handlers/compat')
-rw-r--r-- | pkg/api/handlers/compat/networks.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go index 80b7505df..87b947549 100644 --- a/pkg/api/handlers/compat/networks.go +++ b/pkg/api/handlers/compat/networks.go @@ -5,6 +5,7 @@ import ( "net" "net/http" "os" + "strings" "syscall" "time" @@ -177,9 +178,11 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) { utils.InternalServerError(w, err) return } + + filterNames, nameFilterExists := query.Filters["name"] // TODO remove when filters are implemented - if len(query.Filters) > 0 { - utils.InternalServerError(w, errors.New("filters for listing networks is not implemented")) + if (!nameFilterExists && len(query.Filters) > 0) || len(query.Filters) > 1 { + utils.InternalServerError(w, errors.New("only the name filter for listing networks is implemented")) return } netNames, err := network.GetNetworkNamesFromFileSystem(config) @@ -187,6 +190,21 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) { utils.InternalServerError(w, err) return } + + // filter by name + if nameFilterExists { + names := []string{} + for _, name := range netNames { + for _, filter := range filterNames { + if strings.Contains(name, filter) { + names = append(names, name) + break + } + } + } + netNames = names + } + reports := make([]*types.NetworkResource, 0, len(netNames)) for _, name := range netNames { report, err := getNetworkResourceByName(name, runtime) |