mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #31529 from yongtang/31324-network-ls-filter-scope
Add `--filter scope=swarm|local` for `docker network ls`
This commit is contained in:
commit
4e290f7a2b
7 changed files with 98 additions and 2 deletions
|
@ -59,6 +59,11 @@ func filterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.N
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if filter.Include("scope") {
|
||||||
|
if !filter.ExactMatch("scope", nw.Scope) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
displayNet = append(displayNet, nw)
|
displayNet = append(displayNet, nw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,22 +15,32 @@ func TestFilterNetworks(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "host",
|
Name: "host",
|
||||||
Driver: "host",
|
Driver: "host",
|
||||||
|
Scope: "local",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "bridge",
|
Name: "bridge",
|
||||||
Driver: "bridge",
|
Driver: "bridge",
|
||||||
|
Scope: "local",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "none",
|
Name: "none",
|
||||||
Driver: "null",
|
Driver: "null",
|
||||||
|
Scope: "local",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "myoverlay",
|
Name: "myoverlay",
|
||||||
Driver: "overlay",
|
Driver: "overlay",
|
||||||
|
Scope: "swarm",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "mydrivernet",
|
Name: "mydrivernet",
|
||||||
Driver: "mydriver",
|
Driver: "mydriver",
|
||||||
|
Scope: "local",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "mykvnet",
|
||||||
|
Driver: "mykvdriver",
|
||||||
|
Scope: "global",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +62,15 @@ func TestFilterNetworks(t *testing.T) {
|
||||||
invalidDriverFilters := filters.NewArgs()
|
invalidDriverFilters := filters.NewArgs()
|
||||||
invalidDriverFilters.Add("type", "invalid")
|
invalidDriverFilters.Add("type", "invalid")
|
||||||
|
|
||||||
|
localScopeFilters := filters.NewArgs()
|
||||||
|
localScopeFilters.Add("scope", "local")
|
||||||
|
|
||||||
|
swarmScopeFilters := filters.NewArgs()
|
||||||
|
swarmScopeFilters.Add("scope", "swarm")
|
||||||
|
|
||||||
|
globalScopeFilters := filters.NewArgs()
|
||||||
|
globalScopeFilters.Add("scope", "global")
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
filter filters.Args
|
filter filters.Args
|
||||||
resultCount int
|
resultCount int
|
||||||
|
@ -74,7 +93,7 @@ func TestFilterNetworks(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: customDriverFilters,
|
filter: customDriverFilters,
|
||||||
resultCount: 2,
|
resultCount: 3,
|
||||||
err: "",
|
err: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -87,6 +106,21 @@ func TestFilterNetworks(t *testing.T) {
|
||||||
resultCount: 0,
|
resultCount: 0,
|
||||||
err: "Invalid filter: 'type'='invalid'",
|
err: "Invalid filter: 'type'='invalid'",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filter: localScopeFilters,
|
||||||
|
resultCount: 4,
|
||||||
|
err: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
filter: swarmScopeFilters,
|
||||||
|
resultCount: 1,
|
||||||
|
err: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
filter: globalScopeFilters,
|
||||||
|
resultCount: 1,
|
||||||
|
err: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|
|
@ -27,6 +27,7 @@ var (
|
||||||
"name": true,
|
"name": true,
|
||||||
"id": true,
|
"id": true,
|
||||||
"label": true,
|
"label": true,
|
||||||
|
"scope": true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6269,6 +6269,7 @@ paths:
|
||||||
- `id=<network-id>` Matches all or part of a network ID.
|
- `id=<network-id>` Matches all or part of a network ID.
|
||||||
- `label=<key>` or `label=<key>=<value>` of a network label.
|
- `label=<key>` or `label=<key>=<value>` of a network label.
|
||||||
- `name=<network-name>` Matches all or part of a network name.
|
- `name=<network-name>` Matches all or part of a network name.
|
||||||
|
- `scope=["swarm"|"global"|"local"]` Filters networks by scope (`swarm`, `global`, or `local`).
|
||||||
- `type=["custom"|"builtin"]` Filters networks by type. The `custom` keyword returns all user-defined networks.
|
- `type=["custom"|"builtin"]` Filters networks by type. The `custom` keyword returns all user-defined networks.
|
||||||
type: "string"
|
type: "string"
|
||||||
tags: ["Network"]
|
tags: ["Network"]
|
||||||
|
|
|
@ -13,11 +13,16 @@ keywords: "API, Docker, rcli, REST, documentation"
|
||||||
will be rejected.
|
will be rejected.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
## v1.29 API changes
|
||||||
|
|
||||||
|
[Docker Engine API v1.29](https://docs.docker.com/engine/api/v1.29/) documentation
|
||||||
|
|
||||||
|
* `GET /networks/` now supports a `scope` filter to filter networks based on the network mode (`swarm`, `global`, or `local`).
|
||||||
|
|
||||||
## v1.28 API changes
|
## v1.28 API changes
|
||||||
|
|
||||||
[Docker Engine API v1.28](https://docs.docker.com/engine/api/v1.28/) documentation
|
[Docker Engine API v1.28](https://docs.docker.com/engine/api/v1.28/) documentation
|
||||||
|
|
||||||
|
|
||||||
* `POST /containers/create` now includes a `Consistency` field to specify the consistency level for each `Mount`, with possible values `default`, `consistent`, `cached`, or `delegated`.
|
* `POST /containers/create` now includes a `Consistency` field to specify the consistency level for each `Mount`, with possible values `default`, `consistent`, `cached`, or `delegated`.
|
||||||
* `GET /containers/create` now takes a `DeviceCgroupRules` field in `HostConfig` allowing to set custom device cgroup rules for the created container.
|
* `GET /containers/create` now takes a `DeviceCgroupRules` field in `HostConfig` allowing to set custom device cgroup rules for the created container.
|
||||||
* 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.
|
* 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:
|
||||||
* id (network's id)
|
* id (network's id)
|
||||||
* label (`label=<key>` or `label=<key>=<value>`)
|
* label (`label=<key>` or `label=<key>=<value>`)
|
||||||
* name (network's name)
|
* name (network's name)
|
||||||
|
* scope (`swarm|global|local`)
|
||||||
* type (`custom|builtin`)
|
* type (`custom|builtin`)
|
||||||
|
|
||||||
#### Driver
|
#### Driver
|
||||||
|
@ -157,6 +158,30 @@ NETWORK ID NAME DRIVER SCOPE
|
||||||
06e7eef0a170 foobar bridge local
|
06e7eef0a170 foobar bridge local
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Scope
|
||||||
|
|
||||||
|
The `scope` filter matches networks based on their scope.
|
||||||
|
|
||||||
|
The following example matches networks with the `swarm` scope:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker network ls --filter scope=swarm
|
||||||
|
NETWORK ID NAME DRIVER SCOPE
|
||||||
|
xbtm0v4f1lfh ingress overlay swarm
|
||||||
|
ic6r88twuu92 swarmnet overlay swarm
|
||||||
|
```
|
||||||
|
|
||||||
|
The following example matches networks with the `local` scope:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker network ls --filter scope=local
|
||||||
|
NETWORK ID NAME DRIVER SCOPE
|
||||||
|
e85227439ac7 bridge bridge local
|
||||||
|
0ca0e19443ed host host local
|
||||||
|
ca13cc149a36 localnet bridge local
|
||||||
|
f9e115d2de35 none null local
|
||||||
|
```
|
||||||
|
|
||||||
#### Type
|
#### Type
|
||||||
|
|
||||||
The `type` filter supports two values; `builtin` displays predefined networks
|
The `type` filter supports two values; `builtin` displays predefined networks
|
||||||
|
|
|
@ -35,6 +35,7 @@ The currently supported filters are:
|
||||||
* id (network's id)
|
* id (network's id)
|
||||||
* label (`label=<key>` or `label=<key>=<value>`)
|
* label (`label=<key>` or `label=<key>=<value>`)
|
||||||
* name (network's name)
|
* name (network's name)
|
||||||
|
* scope (`swarm|global|local`)
|
||||||
* type (custom|builtin)
|
* type (custom|builtin)
|
||||||
|
|
||||||
#### Driver
|
#### Driver
|
||||||
|
@ -118,6 +119,30 @@ NETWORK ID NAME DRIVER
|
||||||
06e7eef0a170 foobar bridge
|
06e7eef0a170 foobar bridge
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Scope
|
||||||
|
|
||||||
|
The `scope` filter matches networks based on their scope.
|
||||||
|
|
||||||
|
The following example matches networks with the `swarm` scope:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker network ls --filter scope=swarm
|
||||||
|
NETWORK ID NAME DRIVER SCOPE
|
||||||
|
xbtm0v4f1lfh ingress overlay swarm
|
||||||
|
ic6r88twuu92 swarmnet overlay swarm
|
||||||
|
```
|
||||||
|
|
||||||
|
The following example matches networks with the `local` scope:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker network ls --filter scope=local
|
||||||
|
NETWORK ID NAME DRIVER SCOPE
|
||||||
|
e85227439ac7 bridge bridge local
|
||||||
|
0ca0e19443ed host host local
|
||||||
|
ca13cc149a36 localnet bridge local
|
||||||
|
f9e115d2de35 none null local
|
||||||
|
```
|
||||||
|
|
||||||
#### Type
|
#### Type
|
||||||
|
|
||||||
The `type` filter supports two values; `builtin` displays predefined networks
|
The `type` filter supports two values; `builtin` displays predefined networks
|
||||||
|
|
Loading…
Add table
Reference in a new issue