-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add filter for network ls
to hide predefined network
#17782
Conversation
I understand the use case, but to be in line with other "lists", I'd prefer this to be implemented as a filter, I.e. haven't thought about what to call the filter :-) |
I understand the use case, but flags, flags, more flags, ... I don't think it's worth it =/ Sorry I'm leaning toward -1. |
I do agree with @icecrime on adding another flag, -1 on that — but I understand the use case and I like the idea of the The name of the filter could be |
@WeiZhang555 Would you be willing to update to use a |
Yeah, I can update it with a Actually I have considered these two very different implementations, I mean one more option vs What's more is that comparing to As for consistency, ( However, I won't argue if you all think |
33280f1
to
7d605f5
Compare
I just renamed original option But I'm still waiting for your opinions, and I won't mind to change is to filter format if you insist. 😄 |
7d605f5
to
2cdb26f
Compare
I just re-implemented Currently filter support only two options: Final behavior look likes this:
|
Thanks @WeiZhang555! I understand that "shorter" options can be convenient, but I think we should be consistent; also design (UX) LGTM |
2cdb26f
to
4053699
Compare
network ls
to hide predefined networknetwork ls
to hide predefined network
4053699
to
8c51a71
Compare
Docs updated. |
@WeiZhang555 The UX looks good to me but this should be implemented on the "server" side, as anything the Once this is done, I'll put this into code review 😉. |
@vdemeester OK, I'll move the filter function to server side, as soon as I come back from DockerCon in Europe. 😜 |
Nice! In the airplane now to Barcelona, so see you there! (@vdemeester will be there as well \o/) |
@thaJeztah @vdemeester Look forward to seeing you guys 😆 |
|
||
var supportedFilters map[string]filterHandlers | ||
|
||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can initialize those supported filters directly when you create the variable, two lines above. This init function is not necessary.
I might be wrong, but I feel like the filter validations should be on the server side. Otherwise, people using the API won't have them. |
agreed with @calavera, validations should be server side |
8c51a71
to
89f5a60
Compare
Hello everyone, I have reimplemented this function on server-side, I think it should work fine .
Hmm, there are already two existing filters though not enabled, I'm not sure who are using it. They are
I don't know what it's designed for, so I just keep it there. |
@@ -17,6 +17,68 @@ import ( | |||
"github.com/docker/libnetwork" | |||
) | |||
|
|||
// supportedFilters predefined some supported filter handler function | |||
type filterHandler func(libnetwork.Network, []string) (bool, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we put all this filtering logic in a separated file, like api/server/router/network/filters.go
? just to keep them separated from the routes 😄
00bc8fa
to
185046d
Compare
Rebased on the new client library @calavera And @thaJeztah , partial name match is implemented on https://github.com/docker/docker/pull/17782/files#diff-c5b0cdb16e32c93e45e51c5131209cbaR68, with relevant test case change on https://github.com/docker/docker/pull/17782/files#diff-401699de8561309143baebae1c3696e3R289. Also docs are updated as per your suggestions. Also ping other guys involved, please take a look. 😄 |
Still LGTM for me 😉 |
$ docker network ls --filter name=foo | ||
NETWORK ID NAME DRIVER | ||
95e74588f40d foo bridge | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have partial matches, can you update this to:
#### Name
The `name` filter matches on all or part of a network's name.
The following filter matches all networks with a name containing the `foobar` string.
```bash
$ docker network ls --filter name=foobar
NETWORK ID NAME DRIVER
06e7eef0a170 foobar bridge
```
You can also filter for a substring in a name as this shows:
```bash
$ docker ps --filter name=foo
NETWORK ID NAME DRIVER
95e74588f40d foo bridge
06e7eef0a170 foobar bridge
```
@WeiZhang555 just realized; this is now done server-side? If so, we need to update the API docs as well; In the API changelog, add something like:
The |
185046d
to
69f574f
Compare
@thaJeztah docs updated. And I happen to find that all the filter descriptions are outdated, e.g.
It's not a |
ping @calavera can you check that, is that a deliberate change, because that isn't documented (and sounds like a breaking change in the API) |
ping @calavera |
the api still supports |
hm, perhaps it's better to keep the old description then. not sure we want to describe that "you can either formatA or formatB" Would you be okay changing those descriptions back @WeiZhang555? |
1943873
to
b76ef54
Compare
@thaJeztah Filter descriptions have been changed back already, please take a look. :) |
b76ef54
to
f880711
Compare
Thanks @WeiZhang555! LGTM ping @moxiegirl for a final look 👍 |
Query Parameters: | ||
|
||
- **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the networks list. Available filters: `name=[network-names]` , `id=[network-ids]` | ||
- **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the networks list. Available filters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WeiZhang555 I'm not sure it is necessary to mention the format if there are only limited types of filters. Also, can a user filter on multiple names or ids or only one at a time? Looks like one at a time with multiple filters allowed. So...
- **filters** - JSON encoded network list filter. The filter value is one of:
- `name=<network-name>` Matches all or part of a network name.
- `id=<network-id>` Matches all or part of a network id.
- `type=["custom"|"bridge"|"none"|"host"]` Filters networks by type. The
`custom` keyword returns all user-defined networks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's consistent with the way it's documented for other filters though, e.g. For list containers. Perhaps we should rewrite them all, and provide some actual examples
f880711
to
849ad1b
Compare
@moxiegirl docs updated. |
Add filter support for `network ls` to hide predefined network, then user can use "docker network rm `docker network ls -f type=custom`" to delete a bundle of userdefined networks. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
849ad1b
to
26dd026
Compare
Thanks @WeiZhang555, given that those changes are what @moxiegirl suggested, I take that as an implicit "LGTM" from @moxiegirl, and I think this is ready to merge! LGTM from me as well thanks for your contribution, @WeiZhang555!! |
Add filter for `network ls` to hide predefined network
Add option
--no-predefined
fornetwork ls
to hide predefined network.If will be extremely useful when user want to run "docker network rm
docker network ls -q --no-predefined
" to delete a bundle of networks, without this change, this deletion will always return non-zero exit code which usually indicates error happens because predefined network cant be removed.Signed-off-by: Zhang Wei zhangwei555@huawei.com
Docs are still on working, will be posted after some time.