api/types/network: move connect/disconnect options types to client module

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This commit is contained in:
Austin Vazquez
2025-08-26 14:44:57 -05:00
parent ed8a6a89ca
commit 1e249cc309
15 changed files with 66 additions and 44 deletions

View File

@@ -45,20 +45,6 @@ type CreateOptions struct {
Labels map[string]string // Labels holds metadata specific to the network being created.
}
// ConnectOptions represents the data to be used to connect a container to the
// network.
type ConnectOptions struct {
Container string
EndpointConfig *EndpointSettings `json:",omitempty"`
}
// DisconnectOptions represents the data to be used to disconnect a container
// from the network.
type DisconnectOptions struct {
Container string
Force bool
}
// Inspect is the body of the "get network" http response message.
type Inspect struct {
Name string // Name is the name of the network

View File

@@ -18,7 +18,7 @@ func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID st
return err
}
nc := network.ConnectOptions{
nc := NetworkConnectOptions{
Container: containerID,
EndpointConfig: config,
}

View File

@@ -0,0 +1,10 @@
package client
import "github.com/moby/moby/api/types/network"
// NetworkConnectOptions represents the data to be used to connect a container to the
// network.
type NetworkConnectOptions struct {
Container string
EndpointConfig *network.EndpointSettings `json:",omitempty"`
}

View File

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

View File

@@ -2,8 +2,6 @@ package client
import (
"context"
"github.com/moby/moby/api/types/network"
)
// 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
return err
}
nd := network.DisconnectOptions{
nd := NetworkDisconnectOptions{
Container: containerID,
Force: force,
}

View File

@@ -0,0 +1,8 @@
package client
// NetworkDisconnectOptions represents the data to be used to disconnect a container
// from the network.
type NetworkDisconnectOptions struct {
Container string
Force bool
}

View File

@@ -11,7 +11,6 @@ import (
"testing"
cerrdefs "github.com/containerd/errdefs"
"github.com/moby/moby/api/types/network"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@@ -47,7 +46,7 @@ func TestNetworkDisconnect(t *testing.T) {
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
}
var disconnect network.DisconnectOptions
var disconnect NetworkDisconnectOptions
if err := json.NewDecoder(req.Body).Decode(&disconnect); err != nil {
return nil, err
}

View File

@@ -0,0 +1,17 @@
package networkbackend
import "github.com/moby/moby/api/types/network"
// ConnectOptions represents the data to be used to connect a container to the
// network.
type ConnectOptions struct {
Container string
EndpointConfig *network.EndpointSettings `json:",omitempty"`
}
// DisconnectOptions represents the data to be used to disconnect a container
// from the network.
type DisconnectOptions struct {
Container string
Force bool
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/moby/moby/v2/daemon/libnetwork/scope"
"github.com/moby/moby/v2/daemon/server/backend"
"github.com/moby/moby/v2/daemon/server/httputils"
"github.com/moby/moby/v2/daemon/server/networkbackend"
"github.com/moby/moby/v2/errdefs"
"github.com/pkg/errors"
)
@@ -245,7 +246,7 @@ func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseW
return err
}
var connect network.ConnectOptions
var connect networkbackend.ConnectOptions
if err := httputils.ReadJSON(r, &connect); err != nil {
return err
}
@@ -262,7 +263,7 @@ func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.Respon
return err
}
var disconnect network.DisconnectOptions
var disconnect networkbackend.DisconnectOptions
if err := httputils.ReadJSON(r, &disconnect); err != nil {
return err
}

View File

@@ -11,6 +11,7 @@ import (
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/client"
"github.com/moby/moby/v2/integration-cli/cli"
"github.com/moby/moby/v2/testutil"
"github.com/moby/moby/v2/testutil/request"
@@ -289,7 +290,7 @@ func createNetwork(t *testing.T, config network.CreateRequest, expectedStatusCod
}
func connectNetwork(t *testing.T, nid, cid string) {
resp, _, err := request.Post(testutil.GetContext(t), "/networks/"+nid+"/connect", request.JSONBody(network.ConnectOptions{
resp, _, err := request.Post(testutil.GetContext(t), "/networks/"+nid+"/connect", request.JSONBody(client.NetworkConnectOptions{
Container: cid,
}))
assert.NilError(t, err)
@@ -297,7 +298,7 @@ func connectNetwork(t *testing.T, nid, cid string) {
}
func disconnectNetwork(t *testing.T, nid, cid string) {
config := network.ConnectOptions{
config := client.NetworkDisconnectOptions{
Container: cid,
}

View File

@@ -45,20 +45,6 @@ type CreateOptions struct {
Labels map[string]string // Labels holds metadata specific to the network being created.
}
// ConnectOptions represents the data to be used to connect a container to the
// network.
type ConnectOptions struct {
Container string
EndpointConfig *EndpointSettings `json:",omitempty"`
}
// DisconnectOptions represents the data to be used to disconnect a container
// from the network.
type DisconnectOptions struct {
Container string
Force bool
}
// Inspect is the body of the "get network" http response message.
type Inspect struct {
Name string // Name is the name of the network

View File

@@ -18,7 +18,7 @@ func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID st
return err
}
nc := network.ConnectOptions{
nc := NetworkConnectOptions{
Container: containerID,
EndpointConfig: config,
}

View File

@@ -0,0 +1,10 @@
package client
import "github.com/moby/moby/api/types/network"
// NetworkConnectOptions represents the data to be used to connect a container to the
// network.
type NetworkConnectOptions struct {
Container string
EndpointConfig *network.EndpointSettings `json:",omitempty"`
}

View File

@@ -2,8 +2,6 @@ package client
import (
"context"
"github.com/moby/moby/api/types/network"
)
// 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
return err
}
nd := network.DisconnectOptions{
nd := NetworkDisconnectOptions{
Container: containerID,
Force: force,
}

View File

@@ -0,0 +1,8 @@
package client
// NetworkDisconnectOptions represents the data to be used to disconnect a container
// from the network.
type NetworkDisconnectOptions struct {
Container string
Force bool
}