Skip to content

Commit 1e249cc

Browse files
committed
api/types/network: move connect/disconnect options types to client module
Signed-off-by: Austin Vazquez <[email protected]>
1 parent ed8a6a8 commit 1e249cc

15 files changed

Lines changed: 66 additions & 44 deletions

File tree

api/types/network/network.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,6 @@ type CreateOptions struct {
4545
Labels map[string]string // Labels holds metadata specific to the network being created.
4646
}
4747

48-
// ConnectOptions represents the data to be used to connect a container to the
49-
// network.
50-
type ConnectOptions struct {
51-
Container string
52-
EndpointConfig *EndpointSettings `json:",omitempty"`
53-
}
54-
55-
// DisconnectOptions represents the data to be used to disconnect a container
56-
// from the network.
57-
type DisconnectOptions struct {
58-
Container string
59-
Force bool
60-
}
61-
6248
// Inspect is the body of the "get network" http response message.
6349
type Inspect struct {
6450
Name string // Name is the name of the network

client/network_connect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID st
1818
return err
1919
}
2020

21-
nc := network.ConnectOptions{
21+
nc := NetworkConnectOptions{
2222
Container: containerID,
2323
EndpointConfig: config,
2424
}

client/network_connect_opts.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package client
2+
3+
import "github.com/moby/moby/api/types/network"
4+
5+
// NetworkConnectOptions represents the data to be used to connect a container to the
6+
// network.
7+
type NetworkConnectOptions struct {
8+
Container string
9+
EndpointConfig *network.EndpointSettings `json:",omitempty"`
10+
}

client/network_connect_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestNetworkConnectEmptyNilEndpointSettings(t *testing.T) {
4747
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
4848
}
4949

50-
var connect network.ConnectOptions
50+
var connect NetworkConnectOptions
5151
if err := json.NewDecoder(req.Body).Decode(&connect); err != nil {
5252
return nil, err
5353
}
@@ -84,7 +84,7 @@ func TestNetworkConnect(t *testing.T) {
8484
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
8585
}
8686

87-
var connect network.ConnectOptions
87+
var connect NetworkConnectOptions
8888
if err := json.NewDecoder(req.Body).Decode(&connect); err != nil {
8989
return nil, err
9090
}

client/network_disconnect.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package client
22

33
import (
44
"context"
5-
6-
"github.com/moby/moby/api/types/network"
75
)
86

97
// NetworkDisconnect disconnects a container from an existent network in the docker host.
@@ -18,7 +16,7 @@ func (cli *Client) NetworkDisconnect(ctx context.Context, networkID, containerID
1816
return err
1917
}
2018

21-
nd := network.DisconnectOptions{
19+
nd := NetworkDisconnectOptions{
2220
Container: containerID,
2321
Force: force,
2422
}

client/network_disconnect_opts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package client
2+
3+
// NetworkDisconnectOptions represents the data to be used to disconnect a container
4+
// from the network.
5+
type NetworkDisconnectOptions struct {
6+
Container string
7+
Force bool
8+
}

client/network_disconnect_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212

1313
cerrdefs "github.com/containerd/errdefs"
14-
"github.com/moby/moby/api/types/network"
1514
"gotest.tools/v3/assert"
1615
is "gotest.tools/v3/assert/cmp"
1716
)
@@ -47,7 +46,7 @@ func TestNetworkDisconnect(t *testing.T) {
4746
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
4847
}
4948

50-
var disconnect network.DisconnectOptions
49+
var disconnect NetworkDisconnectOptions
5150
if err := json.NewDecoder(req.Body).Decode(&disconnect); err != nil {
5251
return nil, err
5352
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package networkbackend
2+
3+
import "github.com/moby/moby/api/types/network"
4+
5+
// ConnectOptions represents the data to be used to connect a container to the
6+
// network.
7+
type ConnectOptions struct {
8+
Container string
9+
EndpointConfig *network.EndpointSettings `json:",omitempty"`
10+
}
11+
12+
// DisconnectOptions represents the data to be used to disconnect a container
13+
// from the network.
14+
type DisconnectOptions struct {
15+
Container string
16+
Force bool
17+
}

daemon/server/router/network/network_routes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/moby/moby/v2/daemon/libnetwork/scope"
1414
"github.com/moby/moby/v2/daemon/server/backend"
1515
"github.com/moby/moby/v2/daemon/server/httputils"
16+
"github.com/moby/moby/v2/daemon/server/networkbackend"
1617
"github.com/moby/moby/v2/errdefs"
1718
"github.com/pkg/errors"
1819
)
@@ -245,7 +246,7 @@ func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseW
245246
return err
246247
}
247248

248-
var connect network.ConnectOptions
249+
var connect networkbackend.ConnectOptions
249250
if err := httputils.ReadJSON(r, &connect); err != nil {
250251
return err
251252
}
@@ -262,7 +263,7 @@ func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.Respon
262263
return err
263264
}
264265

265-
var disconnect network.DisconnectOptions
266+
var disconnect networkbackend.DisconnectOptions
266267
if err := httputils.ReadJSON(r, &disconnect); err != nil {
267268
return err
268269
}

integration-cli/docker_api_network_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/moby/moby/api/types/filters"
1313
"github.com/moby/moby/api/types/network"
14+
"github.com/moby/moby/client"
1415
"github.com/moby/moby/v2/integration-cli/cli"
1516
"github.com/moby/moby/v2/testutil"
1617
"github.com/moby/moby/v2/testutil/request"
@@ -289,15 +290,15 @@ func createNetwork(t *testing.T, config network.CreateRequest, expectedStatusCod
289290
}
290291

291292
func connectNetwork(t *testing.T, nid, cid string) {
292-
resp, _, err := request.Post(testutil.GetContext(t), "/networks/"+nid+"/connect", request.JSONBody(network.ConnectOptions{
293+
resp, _, err := request.Post(testutil.GetContext(t), "/networks/"+nid+"/connect", request.JSONBody(client.NetworkConnectOptions{
293294
Container: cid,
294295
}))
295296
assert.NilError(t, err)
296297
assert.Equal(t, resp.StatusCode, http.StatusOK)
297298
}
298299

299300
func disconnectNetwork(t *testing.T, nid, cid string) {
300-
config := network.ConnectOptions{
301+
config := client.NetworkDisconnectOptions{
301302
Container: cid,
302303
}
303304

0 commit comments

Comments
 (0)