summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat/networks.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-09-10 10:15:01 -0400
committerGitHub <noreply@github.com>2020-09-10 10:15:01 -0400
commit3d33923374ee39977166d9fff3ee53c58d884bbe (patch)
tree327b33269b94c9d1faec38eaedf5b78a12a26214 /pkg/api/handlers/compat/networks.go
parente1b47296daaf4148d9970b59757a86e71bf8bb10 (diff)
parentce7d2bba1f6fdc96ef7439135b3c1388b7bac297 (diff)
downloadpodman-3d33923374ee39977166d9fff3ee53c58d884bbe.tar.gz
podman-3d33923374ee39977166d9fff3ee53c58d884bbe.tar.bz2
podman-3d33923374ee39977166d9fff3ee53c58d884bbe.zip
Merge pull request #7536 from Luap99/api-network-filter
APIv2 Add network list filtering
Diffstat (limited to 'pkg/api/handlers/compat/networks.go')
-rw-r--r--pkg/api/handlers/compat/networks.go22
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)