mirror of
https://github.com/moby/moby.git
synced 2026-08-03 22:51:03 +00:00
api/types/network: move ListOptions to client
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This commit is contained in:
@@ -45,11 +45,6 @@ type CreateOptions struct {
|
||||
Labels map[string]string // Labels holds metadata specific to the network being created.
|
||||
}
|
||||
|
||||
// ListOptions holds parameters to filter the list of networks with.
|
||||
type ListOptions struct {
|
||||
Filters filters.Args
|
||||
}
|
||||
|
||||
// InspectOptions holds parameters to inspect network.
|
||||
type InspectOptions struct {
|
||||
Scope string
|
||||
|
||||
@@ -133,7 +133,7 @@ type NetworkAPIClient interface {
|
||||
NetworkDisconnect(ctx context.Context, network, container string, force bool) error
|
||||
NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, error)
|
||||
NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, []byte, error)
|
||||
NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
|
||||
NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error)
|
||||
NetworkRemove(ctx context.Context, network string) error
|
||||
NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// NetworkList returns the list of networks configured in the docker host.
|
||||
func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
|
||||
func (cli *Client) NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error) {
|
||||
query := url.Values{}
|
||||
if options.Filters.Len() > 0 {
|
||||
filterJSON, err := filters.ToJSON(options.Filters)
|
||||
|
||||
8
client/network_list_opts.go
Normal file
8
client/network_list_opts.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package client
|
||||
|
||||
import "github.com/moby/moby/api/types/filters"
|
||||
|
||||
// ListOptions holds parameters to filter the list of networks with.
|
||||
type ListOptions struct {
|
||||
Filters filters.Args
|
||||
}
|
||||
@@ -22,7 +22,7 @@ func TestNetworkListError(t *testing.T) {
|
||||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
|
||||
_, err := client.NetworkList(context.Background(), network.ListOptions{})
|
||||
_, err := client.NetworkList(context.Background(), ListOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
}
|
||||
|
||||
@@ -30,27 +30,27 @@ func TestNetworkList(t *testing.T) {
|
||||
const expectedURL = "/networks"
|
||||
|
||||
listCases := []struct {
|
||||
options network.ListOptions
|
||||
options ListOptions
|
||||
expectedFilters string
|
||||
}{
|
||||
{
|
||||
options: network.ListOptions{},
|
||||
options: ListOptions{},
|
||||
expectedFilters: "",
|
||||
},
|
||||
{
|
||||
options: network.ListOptions{
|
||||
options: ListOptions{
|
||||
Filters: filters.NewArgs(filters.Arg("dangling", "false")),
|
||||
},
|
||||
expectedFilters: `{"dangling":{"false":true}}`,
|
||||
},
|
||||
{
|
||||
options: network.ListOptions{
|
||||
options: ListOptions{
|
||||
Filters: filters.NewArgs(filters.Arg("dangling", "true")),
|
||||
},
|
||||
expectedFilters: `{"dangling":{"true":true}}`,
|
||||
},
|
||||
{
|
||||
options: network.ListOptions{
|
||||
options: ListOptions{
|
||||
Filters: filters.NewArgs(
|
||||
filters.Arg("label", "label1"),
|
||||
filters.Arg("label", "label2"),
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/v2/plugins"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/integration-cli/cli"
|
||||
@@ -36,7 +35,7 @@ func OnlyDefaultNetworks(ctx context.Context) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
networks, err := apiClient.NetworkList(ctx, network.ListOptions{})
|
||||
networks, err := apiClient.NetworkList(ctx, client.ListOptions{})
|
||||
if err != nil || len(networks) > 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func createAmbiguousNetworks(ctx context.Context, t *testing.T, apiClient client
|
||||
idPrefixNet := network.CreateNoError(ctx, t, apiClient, testNet[:12])
|
||||
fullIDNet := network.CreateNoError(ctx, t, apiClient, testNet)
|
||||
|
||||
nws, err := apiClient.NetworkList(ctx, networktypes.ListOptions{})
|
||||
nws, err := apiClient.NetworkList(ctx, client.ListOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Check(t, is.Equal(true, containsNetwork(nws, testNet)), "failed to create network testNet")
|
||||
@@ -79,7 +79,7 @@ func TestDockerNetworkDeletePreferID(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// networks "testNet" and "idPrefixNet" should be removed, but "fullIDNet" should still exist
|
||||
nws, err := apiClient.NetworkList(ctx, networktypes.ListOptions{})
|
||||
nws, err := apiClient.NetworkList(ctx, client.ListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(false, containsNetwork(nws, testNet)), "Network testNet not removed")
|
||||
assert.Check(t, is.Equal(false, containsNetwork(nws, idPrefixNet)), "Network idPrefixNet not removed")
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/testutil"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
@@ -54,7 +53,7 @@ func LinkDoesntExist(ctx context.Context, t *testing.T, master string) {
|
||||
// IsNetworkAvailable provides a comparison to check if a docker network is available
|
||||
func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) is.Comparison {
|
||||
return func() is.Result {
|
||||
networks, err := c.NetworkList(ctx, network.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
if err != nil {
|
||||
return is.ResultFromError(err)
|
||||
}
|
||||
@@ -70,7 +69,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
|
||||
// IsNetworkNotAvailable provides a comparison to check if a docker network is not available
|
||||
func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) is.Comparison {
|
||||
return func() is.Result {
|
||||
networks, err := c.NetworkList(ctx, network.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
if err != nil {
|
||||
return is.ResultFromError(err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
"gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
@@ -12,7 +11,7 @@ import (
|
||||
// IsNetworkAvailable provides a comparison to check if a docker network is available
|
||||
func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
|
||||
return func() cmp.Result {
|
||||
networks, err := c.NetworkList(ctx, network.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
if err != nil {
|
||||
return cmp.ResultFromError(err)
|
||||
}
|
||||
@@ -28,7 +27,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
|
||||
// IsNetworkNotAvailable provides a comparison to check if a docker network is not available
|
||||
func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
|
||||
return func() cmp.Result {
|
||||
networks, err := c.NetworkList(ctx, network.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
if err != nil {
|
||||
return cmp.ResultFromError(err)
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func deleteAllVolumes(ctx context.Context, t testing.TB, c client.VolumeAPIClien
|
||||
|
||||
func deleteAllNetworks(ctx context.Context, t testing.TB, c client.NetworkAPIClient, daemonPlatform string, protectedNetworks map[string]struct{}) {
|
||||
t.Helper()
|
||||
networks, err := c.NetworkList(ctx, network.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
assert.Check(t, err, "failed to list networks")
|
||||
|
||||
for _, n := range networks {
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/moby/moby/api/types/container"
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
"github.com/moby/moby/api/types/image"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/testutil"
|
||||
"go.opentelemetry.io/otel"
|
||||
@@ -168,8 +167,8 @@ func ProtectNetworks(ctx context.Context, t testing.TB, testEnv *Execution) {
|
||||
|
||||
func getExistingNetworks(ctx context.Context, t testing.TB, testEnv *Execution) []string {
|
||||
t.Helper()
|
||||
client := testEnv.APIClient()
|
||||
networkList, err := client.NetworkList(ctx, network.ListOptions{})
|
||||
apiClient := testEnv.APIClient()
|
||||
networkList, err := apiClient.NetworkList(ctx, client.ListOptions{})
|
||||
assert.NilError(t, err, "failed to list networks")
|
||||
|
||||
var networks []string
|
||||
|
||||
5
vendor/github.com/moby/moby/api/types/network/network.go
generated
vendored
5
vendor/github.com/moby/moby/api/types/network/network.go
generated
vendored
@@ -45,11 +45,6 @@ type CreateOptions struct {
|
||||
Labels map[string]string // Labels holds metadata specific to the network being created.
|
||||
}
|
||||
|
||||
// ListOptions holds parameters to filter the list of networks with.
|
||||
type ListOptions struct {
|
||||
Filters filters.Args
|
||||
}
|
||||
|
||||
// InspectOptions holds parameters to inspect network.
|
||||
type InspectOptions struct {
|
||||
Scope string
|
||||
|
||||
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
@@ -133,7 +133,7 @@ type NetworkAPIClient interface {
|
||||
NetworkDisconnect(ctx context.Context, network, container string, force bool) error
|
||||
NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, error)
|
||||
NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, []byte, error)
|
||||
NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
|
||||
NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error)
|
||||
NetworkRemove(ctx context.Context, network string) error
|
||||
NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error)
|
||||
}
|
||||
|
||||
2
vendor/github.com/moby/moby/client/network_list.go
generated
vendored
2
vendor/github.com/moby/moby/client/network_list.go
generated
vendored
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// NetworkList returns the list of networks configured in the docker host.
|
||||
func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
|
||||
func (cli *Client) NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error) {
|
||||
query := url.Values{}
|
||||
if options.Filters.Len() > 0 {
|
||||
filterJSON, err := filters.ToJSON(options.Filters)
|
||||
|
||||
8
vendor/github.com/moby/moby/client/network_list_opts.go
generated
vendored
Normal file
8
vendor/github.com/moby/moby/client/network_list_opts.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
package client
|
||||
|
||||
import "github.com/moby/moby/api/types/filters"
|
||||
|
||||
// ListOptions holds parameters to filter the list of networks with.
|
||||
type ListOptions struct {
|
||||
Filters filters.Args
|
||||
}
|
||||
Reference in New Issue
Block a user