vendor: github.com/moby/moby/api, moby/moby/client master
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -10,8 +10,8 @@ import (
|
||||
type fakeClient struct {
|
||||
client.Client
|
||||
networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error)
|
||||
networkConnectFunc func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error
|
||||
networkDisconnectFunc func(ctx context.Context, networkID, container string, force bool) error
|
||||
networkConnectFunc func(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error)
|
||||
networkDisconnectFunc func(ctx context.Context, networkID string, options client.NetworkDisconnectOptions) (client.NetworkDisconnectResult, error)
|
||||
networkRemoveFunc func(ctx context.Context, networkID string) error
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error)
|
||||
networkPruneFunc func(ctx context.Context, options client.NetworkPruneOptions) (client.NetworkPruneResult, error)
|
||||
@ -25,18 +25,18 @@ func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options cli
|
||||
return network.CreateResponse{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkConnect(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
|
||||
func (c *fakeClient) NetworkConnect(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error) {
|
||||
if c.networkConnectFunc != nil {
|
||||
return c.networkConnectFunc(ctx, networkID, container, config)
|
||||
return c.networkConnectFunc(ctx, networkID, options)
|
||||
}
|
||||
return nil
|
||||
return client.NetworkConnectResult{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error {
|
||||
func (c *fakeClient) NetworkDisconnect(ctx context.Context, networkID string, options client.NetworkDisconnectOptions) (client.NetworkDisconnectResult, error) {
|
||||
if c.networkDisconnectFunc != nil {
|
||||
return c.networkDisconnectFunc(ctx, networkID, container, force)
|
||||
return c.networkDisconnectFunc(ctx, networkID, options)
|
||||
}
|
||||
return nil
|
||||
return client.NetworkDisconnectResult{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error) {
|
||||
@ -46,11 +46,11 @@ func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkList
|
||||
return client.NetworkListResult{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkRemove(ctx context.Context, networkID string) error {
|
||||
func (c *fakeClient) NetworkRemove(ctx context.Context, networkID string, _ client.NetworkRemoveOptions) (client.NetworkRemoveResult, error) {
|
||||
if c.networkRemoveFunc != nil {
|
||||
return c.networkRemoveFunc(ctx, networkID)
|
||||
return client.NetworkRemoveResult{}, c.networkRemoveFunc(ctx, networkID)
|
||||
}
|
||||
return nil
|
||||
return client.NetworkRemoveResult{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkInspect(ctx context.Context, networkID string, opts client.NetworkInspectOptions) (client.NetworkInspectResult, error) {
|
||||
|
||||
@ -68,18 +68,21 @@ func runConnect(ctx context.Context, apiClient client.NetworkAPIClient, options
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return apiClient.NetworkConnect(ctx, options.network, options.container, &network.EndpointSettings{
|
||||
IPAMConfig: &network.EndpointIPAMConfig{
|
||||
IPv4Address: toNetipAddr(options.ipaddress),
|
||||
IPv6Address: toNetipAddr(options.ipv6address),
|
||||
LinkLocalIPs: toNetipAddrSlice(options.linklocalips),
|
||||
_, err = apiClient.NetworkConnect(ctx, options.network, client.NetworkConnectOptions{
|
||||
Container: options.container,
|
||||
EndpointConfig: &network.EndpointSettings{
|
||||
IPAMConfig: &network.EndpointIPAMConfig{
|
||||
IPv4Address: toNetipAddr(options.ipaddress),
|
||||
IPv6Address: toNetipAddr(options.ipv6address),
|
||||
LinkLocalIPs: toNetipAddrSlice(options.linklocalips),
|
||||
},
|
||||
Links: options.links.GetSlice(),
|
||||
Aliases: options.aliases,
|
||||
DriverOpts: driverOpts,
|
||||
GwPriority: options.gwPriority,
|
||||
},
|
||||
Links: options.links.GetSlice(),
|
||||
Aliases: options.aliases,
|
||||
DriverOpts: driverOpts,
|
||||
GwPriority: options.gwPriority,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func convertDriverOpt(options []string) (map[string]string, error) {
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
@ -17,7 +18,7 @@ import (
|
||||
func TestNetworkConnectErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
args []string
|
||||
networkConnectFunc func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error
|
||||
networkConnectFunc func(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error)
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
@ -25,8 +26,8 @@ func TestNetworkConnectErrors(t *testing.T) {
|
||||
},
|
||||
{
|
||||
args: []string{"toto", "titi"},
|
||||
networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
|
||||
return errors.New("error connecting network")
|
||||
networkConnectFunc: func(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error) {
|
||||
return client.NetworkConnectResult{}, errors.New("error connecting network")
|
||||
},
|
||||
expectedError: "error connecting network",
|
||||
},
|
||||
@ -61,9 +62,9 @@ func TestNetworkConnectWithFlags(t *testing.T) {
|
||||
GwPriority: 100,
|
||||
}
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
|
||||
assert.Check(t, is.DeepEqual(expectedConfig, config, cmpopts.EquateComparable(netip.Addr{})))
|
||||
return nil
|
||||
networkConnectFunc: func(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error) {
|
||||
assert.Check(t, is.DeepEqual(expectedConfig, options.EndpointConfig, cmpopts.EquateComparable(netip.Addr{})))
|
||||
return client.NetworkConnectResult{}, nil
|
||||
},
|
||||
})
|
||||
args := []string{"mynet", "myctr"}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/completion"
|
||||
@ -12,9 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type disconnectOptions struct {
|
||||
network string
|
||||
container string
|
||||
force bool
|
||||
force bool
|
||||
}
|
||||
|
||||
func newDisconnectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
@ -25,9 +21,12 @@ func newDisconnectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
Short: "Disconnect a container from a network",
|
||||
Args: cli.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.network = args[0]
|
||||
opts.container = args[1]
|
||||
return runDisconnect(cmd.Context(), dockerCLI.Client(), opts)
|
||||
network := args[0]
|
||||
_, err := dockerCLI.Client().NetworkDisconnect(cmd.Context(), network, client.NetworkDisconnectOptions{
|
||||
Container: args[1],
|
||||
Force: opts.force,
|
||||
})
|
||||
return err
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if len(args) == 0 {
|
||||
@ -45,10 +44,6 @@ func newDisconnectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runDisconnect(ctx context.Context, apiClient client.NetworkAPIClient, opts disconnectOptions) error {
|
||||
return apiClient.NetworkDisconnect(ctx, opts.network, opts.container, opts.force)
|
||||
}
|
||||
|
||||
func isConnected(network string) func(container.Summary) bool {
|
||||
return func(ctr container.Summary) bool {
|
||||
if ctr.NetworkSettings == nil {
|
||||
|
||||
@ -7,13 +7,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/moby/moby/client"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func TestNetworkDisconnectErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
args []string
|
||||
networkDisconnectFunc func(ctx context.Context, networkID, container string, force bool) error
|
||||
networkDisconnectFunc func(ctx context.Context, networkID string, options client.NetworkDisconnectOptions) (client.NetworkDisconnectResult, error)
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
@ -21,8 +22,8 @@ func TestNetworkDisconnectErrors(t *testing.T) {
|
||||
},
|
||||
{
|
||||
args: []string{"toto", "titi"},
|
||||
networkDisconnectFunc: func(ctx context.Context, networkID, container string, force bool) error {
|
||||
return errors.New("error disconnecting network")
|
||||
networkDisconnectFunc: func(ctx context.Context, networkID string, options client.NetworkDisconnectOptions) (client.NetworkDisconnectResult, error) {
|
||||
return client.NetworkDisconnectResult{}, errors.New("error disconnecting network")
|
||||
},
|
||||
expectedError: "error disconnecting network",
|
||||
},
|
||||
|
||||
@ -59,7 +59,8 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, networks []string, op
|
||||
continue
|
||||
}
|
||||
}
|
||||
if err := apiClient.NetworkRemove(ctx, name); err != nil {
|
||||
_, err = apiClient.NetworkRemove(ctx, name, client.NetworkRemoveOptions{})
|
||||
if err != nil {
|
||||
if opts.force && errdefs.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user