This fix tries to address the request in 31324 by adding
`--filter scope=swarm|local` for `docker network ls`.
As `docker network ls` has a `SCOPE` column by default,
it is natural to add the support of `--filter scope=swarm|local`.
This fix adds the `scope=swarm|local` support for
`docker network ls --filter`.
Related docs has been updated.
Additional unit test cases have been added.
This fix fixes 31324.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -59,6 +59,11 @@ func filterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.N |
| 59 | 59 |
continue |
| 60 | 60 |
} |
| 61 | 61 |
} |
| 62 |
+ if filter.Include("scope") {
|
|
| 63 |
+ if !filter.ExactMatch("scope", nw.Scope) {
|
|
| 64 |
+ continue |
|
| 65 |
+ } |
|
| 66 |
+ } |
|
| 62 | 67 |
displayNet = append(displayNet, nw) |
| 63 | 68 |
} |
| 64 | 69 |
|
| ... | ... |
@@ -15,22 +15,32 @@ func TestFilterNetworks(t *testing.T) {
|
| 15 | 15 |
{
|
| 16 | 16 |
Name: "host", |
| 17 | 17 |
Driver: "host", |
| 18 |
+ Scope: "local", |
|
| 18 | 19 |
}, |
| 19 | 20 |
{
|
| 20 | 21 |
Name: "bridge", |
| 21 | 22 |
Driver: "bridge", |
| 23 |
+ Scope: "local", |
|
| 22 | 24 |
}, |
| 23 | 25 |
{
|
| 24 | 26 |
Name: "none", |
| 25 | 27 |
Driver: "null", |
| 28 |
+ Scope: "local", |
|
| 26 | 29 |
}, |
| 27 | 30 |
{
|
| 28 | 31 |
Name: "myoverlay", |
| 29 | 32 |
Driver: "overlay", |
| 33 |
+ Scope: "swarm", |
|
| 30 | 34 |
}, |
| 31 | 35 |
{
|
| 32 | 36 |
Name: "mydrivernet", |
| 33 | 37 |
Driver: "mydriver", |
| 38 |
+ Scope: "local", |
|
| 39 |
+ }, |
|
| 40 |
+ {
|
|
| 41 |
+ Name: "mykvnet", |
|
| 42 |
+ Driver: "mykvdriver", |
|
| 43 |
+ Scope: "global", |
|
| 34 | 44 |
}, |
| 35 | 45 |
} |
| 36 | 46 |
|
| ... | ... |
@@ -52,6 +62,15 @@ func TestFilterNetworks(t *testing.T) {
|
| 52 | 52 |
invalidDriverFilters := filters.NewArgs() |
| 53 | 53 |
invalidDriverFilters.Add("type", "invalid")
|
| 54 | 54 |
|
| 55 |
+ localScopeFilters := filters.NewArgs() |
|
| 56 |
+ localScopeFilters.Add("scope", "local")
|
|
| 57 |
+ |
|
| 58 |
+ swarmScopeFilters := filters.NewArgs() |
|
| 59 |
+ swarmScopeFilters.Add("scope", "swarm")
|
|
| 60 |
+ |
|
| 61 |
+ globalScopeFilters := filters.NewArgs() |
|
| 62 |
+ globalScopeFilters.Add("scope", "global")
|
|
| 63 |
+ |
|
| 55 | 64 |
testCases := []struct {
|
| 56 | 65 |
filter filters.Args |
| 57 | 66 |
resultCount int |
| ... | ... |
@@ -74,7 +93,7 @@ func TestFilterNetworks(t *testing.T) {
|
| 74 | 74 |
}, |
| 75 | 75 |
{
|
| 76 | 76 |
filter: customDriverFilters, |
| 77 |
- resultCount: 2, |
|
| 77 |
+ resultCount: 3, |
|
| 78 | 78 |
err: "", |
| 79 | 79 |
}, |
| 80 | 80 |
{
|
| ... | ... |
@@ -87,6 +106,21 @@ func TestFilterNetworks(t *testing.T) {
|
| 87 | 87 |
resultCount: 0, |
| 88 | 88 |
err: "Invalid filter: 'type'='invalid'", |
| 89 | 89 |
}, |
| 90 |
+ {
|
|
| 91 |
+ filter: localScopeFilters, |
|
| 92 |
+ resultCount: 4, |
|
| 93 |
+ err: "", |
|
| 94 |
+ }, |
|
| 95 |
+ {
|
|
| 96 |
+ filter: swarmScopeFilters, |
|
| 97 |
+ resultCount: 1, |
|
| 98 |
+ err: "", |
|
| 99 |
+ }, |
|
| 100 |
+ {
|
|
| 101 |
+ filter: globalScopeFilters, |
|
| 102 |
+ resultCount: 1, |
|
| 103 |
+ err: "", |
|
| 104 |
+ }, |
|
| 90 | 105 |
} |
| 91 | 106 |
|
| 92 | 107 |
for _, testCase := range testCases {
|
| ... | ... |
@@ -6269,6 +6269,7 @@ paths: |
| 6269 | 6269 |
- `id=<network-id>` Matches all or part of a network ID. |
| 6270 | 6270 |
- `label=<key>` or `label=<key>=<value>` of a network label. |
| 6271 | 6271 |
- `name=<network-name>` Matches all or part of a network name. |
| 6272 |
+ - `scope=["swarm"|"global"|"local"]` Filters networks by scope (`swarm`, `global`, or `local`). |
|
| 6272 | 6273 |
- `type=["custom"|"builtin"]` Filters networks by type. The `custom` keyword returns all user-defined networks. |
| 6273 | 6274 |
type: "string" |
| 6274 | 6275 |
tags: ["Network"] |
| ... | ... |
@@ -13,11 +13,16 @@ keywords: "API, Docker, rcli, REST, documentation" |
| 13 | 13 |
will be rejected. |
| 14 | 14 |
--> |
| 15 | 15 |
|
| 16 |
+## v1.29 API changes |
|
| 17 |
+ |
|
| 18 |
+[Docker Engine API v1.29](https://docs.docker.com/engine/api/v1.29/) documentation |
|
| 19 |
+ |
|
| 20 |
+* `GET /networks/` now supports a `scope` filter to filter networks based on the network mode (`swarm`, `global`, or `local`). |
|
| 21 |
+ |
|
| 16 | 22 |
## v1.28 API changes |
| 17 | 23 |
|
| 18 | 24 |
[Docker Engine API v1.28](https://docs.docker.com/engine/api/v1.28/) documentation |
| 19 | 25 |
|
| 20 |
- |
|
| 21 | 26 |
* `POST /containers/create` now includes a `Consistency` field to specify the consistency level for each `Mount`, with possible values `default`, `consistent`, `cached`, or `delegated`. |
| 22 | 27 |
* `GET /containers/create` now takes a `DeviceCgroupRules` field in `HostConfig` allowing to set custom device cgroup rules for the created container. |
| 23 | 28 |
* Optional query parameter `verbose` for `GET /networks/(id or name)` will now list all services with all the tasks, including the non-local tasks on the given network. |
| ... | ... |
@@ -74,6 +74,7 @@ The currently supported filters are: |
| 74 | 74 |
* id (network's id) |
| 75 | 75 |
* label (`label=<key>` or `label=<key>=<value>`) |
| 76 | 76 |
* name (network's name) |
| 77 |
+* scope (`swarm|global|local`) |
|
| 77 | 78 |
* type (`custom|builtin`) |
| 78 | 79 |
|
| 79 | 80 |
#### Driver |
| ... | ... |
@@ -157,6 +158,30 @@ NETWORK ID NAME DRIVER SCOPE |
| 157 | 157 |
06e7eef0a170 foobar bridge local |
| 158 | 158 |
``` |
| 159 | 159 |
|
| 160 |
+#### Scope |
|
| 161 |
+ |
|
| 162 |
+The `scope` filter matches networks based on their scope. |
|
| 163 |
+ |
|
| 164 |
+The following example matches networks with the `swarm` scope: |
|
| 165 |
+ |
|
| 166 |
+```bash |
|
| 167 |
+$ docker network ls --filter scope=swarm |
|
| 168 |
+NETWORK ID NAME DRIVER SCOPE |
|
| 169 |
+xbtm0v4f1lfh ingress overlay swarm |
|
| 170 |
+ic6r88twuu92 swarmnet overlay swarm |
|
| 171 |
+``` |
|
| 172 |
+ |
|
| 173 |
+The following example matches networks with the `local` scope: |
|
| 174 |
+ |
|
| 175 |
+```bash |
|
| 176 |
+$ docker network ls --filter scope=local |
|
| 177 |
+NETWORK ID NAME DRIVER SCOPE |
|
| 178 |
+e85227439ac7 bridge bridge local |
|
| 179 |
+0ca0e19443ed host host local |
|
| 180 |
+ca13cc149a36 localnet bridge local |
|
| 181 |
+f9e115d2de35 none null local |
|
| 182 |
+``` |
|
| 183 |
+ |
|
| 160 | 184 |
#### Type |
| 161 | 185 |
|
| 162 | 186 |
The `type` filter supports two values; `builtin` displays predefined networks |
| ... | ... |
@@ -35,6 +35,7 @@ The currently supported filters are: |
| 35 | 35 |
* id (network's id) |
| 36 | 36 |
* label (`label=<key>` or `label=<key>=<value>`) |
| 37 | 37 |
* name (network's name) |
| 38 |
+* scope (`swarm|global|local`) |
|
| 38 | 39 |
* type (custom|builtin) |
| 39 | 40 |
|
| 40 | 41 |
#### Driver |
| ... | ... |
@@ -118,6 +119,30 @@ NETWORK ID NAME DRIVER |
| 118 | 118 |
06e7eef0a170 foobar bridge |
| 119 | 119 |
``` |
| 120 | 120 |
|
| 121 |
+#### Scope |
|
| 122 |
+ |
|
| 123 |
+The `scope` filter matches networks based on their scope. |
|
| 124 |
+ |
|
| 125 |
+The following example matches networks with the `swarm` scope: |
|
| 126 |
+ |
|
| 127 |
+```bash |
|
| 128 |
+$ docker network ls --filter scope=swarm |
|
| 129 |
+NETWORK ID NAME DRIVER SCOPE |
|
| 130 |
+xbtm0v4f1lfh ingress overlay swarm |
|
| 131 |
+ic6r88twuu92 swarmnet overlay swarm |
|
| 132 |
+``` |
|
| 133 |
+ |
|
| 134 |
+The following example matches networks with the `local` scope: |
|
| 135 |
+ |
|
| 136 |
+```bash |
|
| 137 |
+$ docker network ls --filter scope=local |
|
| 138 |
+NETWORK ID NAME DRIVER SCOPE |
|
| 139 |
+e85227439ac7 bridge bridge local |
|
| 140 |
+0ca0e19443ed host host local |
|
| 141 |
+ca13cc149a36 localnet bridge local |
|
| 142 |
+f9e115d2de35 none null local |
|
| 143 |
+``` |
|
| 144 |
+ |
|
| 121 | 145 |
#### Type |
| 122 | 146 |
|
| 123 | 147 |
The `type` filter supports two values; `builtin` displays predefined networks |