This moves the type to the api/types/network package, but also introduces
a "Summary" alias; the intent here is to allow diverging the types used
for "list" and "inspect" operations, as list operations may only be
producing a subset of the fields available.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -12,7 +12,7 @@ import ( |
| 12 | 12 |
// Backend is all the methods that need to be implemented |
| 13 | 13 |
// to provide network specific functionality. |
| 14 | 14 |
type Backend interface {
|
| 15 |
- GetNetworks(filters.Args, backend.NetworkListConfig) ([]types.NetworkResource, error) |
|
| 15 |
+ GetNetworks(filters.Args, backend.NetworkListConfig) ([]network.Inspect, error) |
|
| 16 | 16 |
CreateNetwork(nc types.NetworkCreateRequest) (*network.CreateResponse, error) |
| 17 | 17 |
ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error |
| 18 | 18 |
DisconnectContainerFromNetwork(containerName string, networkName string, force bool) error |
| ... | ... |
@@ -23,9 +23,9 @@ type Backend interface {
|
| 23 | 23 |
// ClusterBackend is all the methods that need to be implemented |
| 24 | 24 |
// to provide cluster network specific functionality. |
| 25 | 25 |
type ClusterBackend interface {
|
| 26 |
- GetNetworks(filters.Args) ([]types.NetworkResource, error) |
|
| 27 |
- GetNetwork(name string) (types.NetworkResource, error) |
|
| 28 |
- GetNetworksByName(name string) ([]types.NetworkResource, error) |
|
| 26 |
+ GetNetworks(filters.Args) ([]network.Inspect, error) |
|
| 27 |
+ GetNetwork(name string) (network.Inspect, error) |
|
| 28 |
+ GetNetworksByName(name string) ([]network.Inspect, error) |
|
| 29 | 29 |
CreateNetwork(nc types.NetworkCreateRequest) (string, error) |
| 30 | 30 |
RemoveNetwork(name string) error |
| 31 | 31 |
} |
| ... | ... |
@@ -32,7 +32,7 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit |
| 32 | 32 |
return err |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
- var list []types.NetworkResource |
|
| 35 |
+ var list []network.Summary |
|
| 36 | 36 |
nr, err := n.cluster.GetNetworks(filter) |
| 37 | 37 |
if err == nil {
|
| 38 | 38 |
list = nr |
| ... | ... |
@@ -60,7 +60,7 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 | 62 |
if list == nil {
|
| 63 |
- list = []types.NetworkResource{}
|
|
| 63 |
+ list = []network.Summary{}
|
|
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 | 66 |
return httputils.WriteJSON(w, http.StatusOK, list) |
| ... | ... |
@@ -109,8 +109,8 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r |
| 109 | 109 |
|
| 110 | 110 |
// For full name and partial ID, save the result first, and process later |
| 111 | 111 |
// in case multiple records was found based on the same term |
| 112 |
- listByFullName := map[string]types.NetworkResource{}
|
|
| 113 |
- listByPartialID := map[string]types.NetworkResource{}
|
|
| 112 |
+ listByFullName := map[string]network.Inspect{}
|
|
| 113 |
+ listByPartialID := map[string]network.Inspect{}
|
|
| 114 | 114 |
|
| 115 | 115 |
// TODO(@cpuguy83): All this logic for figuring out which network to return does not belong here |
| 116 | 116 |
// Instead there should be a backend function to just get one network. |
| ... | ... |
@@ -311,9 +311,9 @@ func (n *networkRouter) postNetworksPrune(ctx context.Context, w http.ResponseWr |
| 311 | 311 |
// For full name and partial ID, save the result first, and process later |
| 312 | 312 |
// in case multiple records was found based on the same term |
| 313 | 313 |
// TODO (yongtang): should we wrap with version here for backward compatibility? |
| 314 |
-func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, error) {
|
|
| 315 |
- listByFullName := map[string]types.NetworkResource{}
|
|
| 316 |
- listByPartialID := map[string]types.NetworkResource{}
|
|
| 314 |
+func (n *networkRouter) findUniqueNetwork(term string) (network.Inspect, error) {
|
|
| 315 |
+ listByFullName := map[string]network.Inspect{}
|
|
| 316 |
+ listByPartialID := map[string]network.Inspect{}
|
|
| 317 | 317 |
|
| 318 | 318 |
filter := filters.NewArgs(filters.Arg("idOrName", term))
|
| 319 | 319 |
networks, _ := n.backend.GetNetworks(filter, backend.NetworkListConfig{Detailed: true})
|
| ... | ... |
@@ -363,7 +363,7 @@ func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, e |
| 363 | 363 |
} |
| 364 | 364 |
} |
| 365 | 365 |
if len(listByFullName) > 1 {
|
| 366 |
- return types.NetworkResource{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName)))
|
|
| 366 |
+ return network.Inspect{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName)))
|
|
| 367 | 367 |
} |
| 368 | 368 |
|
| 369 | 369 |
// Find based on partial ID, returns true only if no duplicates |
| ... | ... |
@@ -373,8 +373,8 @@ func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, e |
| 373 | 373 |
} |
| 374 | 374 |
} |
| 375 | 375 |
if len(listByPartialID) > 1 {
|
| 376 |
- return types.NetworkResource{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID)))
|
|
| 376 |
+ return network.Inspect{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID)))
|
|
| 377 | 377 |
} |
| 378 | 378 |
|
| 379 |
- return types.NetworkResource{}, errdefs.NotFound(libnetwork.ErrNoSuchNetwork(term))
|
|
| 379 |
+ return network.Inspect{}, errdefs.NotFound(libnetwork.ErrNoSuchNetwork(term))
|
|
| 380 | 380 |
} |
| ... | ... |
@@ -1,6 +1,8 @@ |
| 1 | 1 |
package network // import "github.com/docker/docker/api/types/network" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "time" |
|
| 5 |
+ |
|
| 4 | 6 |
"github.com/docker/docker/api/types/filters" |
| 5 | 7 |
) |
| 6 | 8 |
|
| ... | ... |
@@ -42,6 +44,32 @@ type DisconnectOptions struct {
|
| 42 | 42 |
Force bool |
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 |
+// Inspect is the body of the "get network" http response message. |
|
| 46 |
+type Inspect struct {
|
|
| 47 |
+ Name string // Name is the name of the network |
|
| 48 |
+ ID string `json:"Id"` // ID uniquely identifies a network on a single machine |
|
| 49 |
+ Created time.Time // Created is the time the network created |
|
| 50 |
+ Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level) |
|
| 51 |
+ Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`) |
|
| 52 |
+ EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6 |
|
| 53 |
+ IPAM IPAM // IPAM is the network's IP Address Management |
|
| 54 |
+ Internal bool // Internal represents if the network is used internal only |
|
| 55 |
+ Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. |
|
| 56 |
+ Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. |
|
| 57 |
+ ConfigFrom ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. |
|
| 58 |
+ ConfigOnly bool // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services. |
|
| 59 |
+ Containers map[string]EndpointResource // Containers contains endpoints belonging to the network |
|
| 60 |
+ Options map[string]string // Options holds the network specific options to use for when creating the network |
|
| 61 |
+ Labels map[string]string // Labels holds metadata specific to the network being created |
|
| 62 |
+ Peers []PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network |
|
| 63 |
+ Services map[string]ServiceInfo `json:",omitempty"` |
|
| 64 |
+} |
|
| 65 |
+ |
|
| 66 |
+// Summary is used as response when listing networks. It currently is an alias |
|
| 67 |
+// for [Inspect], but may diverge in the future, as not all information may |
|
| 68 |
+// be included when listing networks. |
|
| 69 |
+type Summary = Inspect |
|
| 70 |
+ |
|
| 45 | 71 |
// Address represents an IP address |
| 46 | 72 |
type Address struct {
|
| 47 | 73 |
Addr string |
| ... | ... |
@@ -423,27 +423,6 @@ type MountPoint struct {
|
| 423 | 423 |
Propagation mount.Propagation |
| 424 | 424 |
} |
| 425 | 425 |
|
| 426 |
-// NetworkResource is the body of the "get network" http response message |
|
| 427 |
-type NetworkResource struct {
|
|
| 428 |
- Name string // Name is the requested name of the network |
|
| 429 |
- ID string `json:"Id"` // ID uniquely identifies a network on a single machine |
|
| 430 |
- Created time.Time // Created is the time the network created |
|
| 431 |
- Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level) |
|
| 432 |
- Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`) |
|
| 433 |
- EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6 |
|
| 434 |
- IPAM network.IPAM // IPAM is the network's IP Address Management |
|
| 435 |
- Internal bool // Internal represents if the network is used internal only |
|
| 436 |
- Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. |
|
| 437 |
- Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. |
|
| 438 |
- ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. |
|
| 439 |
- ConfigOnly bool // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services. |
|
| 440 |
- Containers map[string]network.EndpointResource // Containers contains endpoints belonging to the network |
|
| 441 |
- Options map[string]string // Options holds the network specific options to use for when creating the network |
|
| 442 |
- Labels map[string]string // Labels holds metadata specific to the network being created |
|
| 443 |
- Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network |
|
| 444 |
- Services map[string]network.ServiceInfo `json:",omitempty"` |
|
| 445 |
-} |
|
| 446 |
- |
|
| 447 | 426 |
// NetworkCreate is the expected body of the "create network" http request message |
| 448 | 427 |
type NetworkCreate struct {
|
| 449 | 428 |
// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client |
| ... | ... |
@@ -33,3 +33,8 @@ type NetworkDisconnect = network.DisconnectOptions |
| 33 | 33 |
// |
| 34 | 34 |
// Deprecated: use [network.EndpointResource]. |
| 35 | 35 |
type EndpointResource = network.EndpointResource |
| 36 |
+ |
|
| 37 |
+// NetworkResource is the body of the "get network" http response message/ |
|
| 38 |
+// |
|
| 39 |
+// Deprecated: use [network.Inspect] or [network.Summary] (for list operations). |
|
| 40 |
+type NetworkResource = network.Inspect |
| ... | ... |
@@ -110,9 +110,9 @@ type NetworkAPIClient interface {
|
| 110 | 110 |
NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error |
| 111 | 111 |
NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (network.CreateResponse, error) |
| 112 | 112 |
NetworkDisconnect(ctx context.Context, network, container string, force bool) error |
| 113 |
- NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (types.NetworkResource, error) |
|
| 114 |
- NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (types.NetworkResource, []byte, error) |
|
| 115 |
- NetworkList(ctx context.Context, options network.ListOptions) ([]types.NetworkResource, error) |
|
| 113 |
+ NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, error) |
|
| 114 |
+ NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, []byte, error) |
|
| 115 |
+ NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) |
|
| 116 | 116 |
NetworkRemove(ctx context.Context, network string) error |
| 117 | 117 |
NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) |
| 118 | 118 |
} |
| ... | ... |
@@ -7,20 +7,19 @@ import ( |
| 7 | 7 |
"io" |
| 8 | 8 |
"net/url" |
| 9 | 9 |
|
| 10 |
- "github.com/docker/docker/api/types" |
|
| 11 | 10 |
"github.com/docker/docker/api/types/network" |
| 12 | 11 |
) |
| 13 | 12 |
|
| 14 | 13 |
// NetworkInspect returns the information for a specific network configured in the docker host. |
| 15 |
-func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (types.NetworkResource, error) {
|
|
| 14 |
+func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) {
|
|
| 16 | 15 |
networkResource, _, err := cli.NetworkInspectWithRaw(ctx, networkID, options) |
| 17 | 16 |
return networkResource, err |
| 18 | 17 |
} |
| 19 | 18 |
|
| 20 | 19 |
// NetworkInspectWithRaw returns the information for a specific network configured in the docker host and its raw representation. |
| 21 |
-func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, options network.InspectOptions) (types.NetworkResource, []byte, error) {
|
|
| 20 |
+func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, []byte, error) {
|
|
| 22 | 21 |
if networkID == "" {
|
| 23 |
- return types.NetworkResource{}, nil, objectNotFoundError{object: "network", id: networkID}
|
|
| 22 |
+ return network.Inspect{}, nil, objectNotFoundError{object: "network", id: networkID}
|
|
| 24 | 23 |
} |
| 25 | 24 |
query := url.Values{}
|
| 26 | 25 |
if options.Verbose {
|
| ... | ... |
@@ -33,15 +32,15 @@ func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, |
| 33 | 33 |
resp, err := cli.get(ctx, "/networks/"+networkID, query, nil) |
| 34 | 34 |
defer ensureReaderClosed(resp) |
| 35 | 35 |
if err != nil {
|
| 36 |
- return types.NetworkResource{}, nil, err
|
|
| 36 |
+ return network.Inspect{}, nil, err
|
|
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 | 39 |
raw, err := io.ReadAll(resp.body) |
| 40 | 40 |
if err != nil {
|
| 41 |
- return types.NetworkResource{}, nil, err
|
|
| 41 |
+ return network.Inspect{}, nil, err
|
|
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
- var nw types.NetworkResource |
|
| 44 |
+ var nw network.Inspect |
|
| 45 | 45 |
err = json.NewDecoder(bytes.NewReader(raw)).Decode(&nw) |
| 46 | 46 |
return nw, raw, err |
| 47 | 47 |
} |
| ... | ... |
@@ -10,7 +10,6 @@ import ( |
| 10 | 10 |
"strings" |
| 11 | 11 |
"testing" |
| 12 | 12 |
|
| 13 |
- "github.com/docker/docker/api/types" |
|
| 14 | 13 |
"github.com/docker/docker/api/types/network" |
| 15 | 14 |
"github.com/docker/docker/errdefs" |
| 16 | 15 |
"gotest.tools/v3/assert" |
| ... | ... |
@@ -47,12 +46,12 @@ func TestNetworkInspect(t *testing.T) {
|
| 47 | 47 |
s := map[string]network.ServiceInfo{
|
| 48 | 48 |
"web": {},
|
| 49 | 49 |
} |
| 50 |
- content, err = json.Marshal(types.NetworkResource{
|
|
| 50 |
+ content, err = json.Marshal(network.Inspect{
|
|
| 51 | 51 |
Name: "mynetwork", |
| 52 | 52 |
Services: s, |
| 53 | 53 |
}) |
| 54 | 54 |
} else {
|
| 55 |
- content, err = json.Marshal(types.NetworkResource{
|
|
| 55 |
+ content, err = json.Marshal(network.Inspect{
|
|
| 56 | 56 |
Name: "mynetwork", |
| 57 | 57 |
}) |
| 58 | 58 |
} |
| ... | ... |
@@ -5,13 +5,12 @@ import ( |
| 5 | 5 |
"encoding/json" |
| 6 | 6 |
"net/url" |
| 7 | 7 |
|
| 8 |
- "github.com/docker/docker/api/types" |
|
| 9 | 8 |
"github.com/docker/docker/api/types/filters" |
| 10 | 9 |
"github.com/docker/docker/api/types/network" |
| 11 | 10 |
) |
| 12 | 11 |
|
| 13 | 12 |
// NetworkList returns the list of networks configured in the docker host. |
| 14 |
-func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]types.NetworkResource, error) {
|
|
| 13 |
+func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
|
|
| 15 | 14 |
query := url.Values{}
|
| 16 | 15 |
if options.Filters.Len() > 0 {
|
| 17 | 16 |
//nolint:staticcheck // ignore SA1019 for old code |
| ... | ... |
@@ -22,7 +21,7 @@ func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) |
| 22 | 22 |
|
| 23 | 23 |
query.Set("filters", filterJSON)
|
| 24 | 24 |
} |
| 25 |
- var networkResources []types.NetworkResource |
|
| 25 |
+ var networkResources []network.Summary |
|
| 26 | 26 |
resp, err := cli.get(ctx, "/networks", query, nil) |
| 27 | 27 |
defer ensureReaderClosed(resp) |
| 28 | 28 |
if err != nil {
|
| ... | ... |
@@ -10,7 +10,6 @@ import ( |
| 10 | 10 |
"strings" |
| 11 | 11 |
"testing" |
| 12 | 12 |
|
| 13 |
- "github.com/docker/docker/api/types" |
|
| 14 | 13 |
"github.com/docker/docker/api/types/filters" |
| 15 | 14 |
"github.com/docker/docker/api/types/network" |
| 16 | 15 |
"github.com/docker/docker/errdefs" |
| ... | ... |
@@ -75,7 +74,7 @@ func TestNetworkList(t *testing.T) {
|
| 75 | 75 |
if actualFilters != listCase.expectedFilters {
|
| 76 | 76 |
return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters)
|
| 77 | 77 |
} |
| 78 |
- content, err := json.Marshal([]types.NetworkResource{
|
|
| 78 |
+ content, err := json.Marshal([]network.Summary{
|
|
| 79 | 79 |
{
|
| 80 | 80 |
Name: "network", |
| 81 | 81 |
Driver: "bridge", |
| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 | 1 |
package daemon // import "github.com/docker/docker/daemon" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- apitypes "github.com/docker/docker/api/types" |
|
| 5 | 4 |
"github.com/docker/docker/api/types/filters" |
| 5 |
+ "github.com/docker/docker/api/types/network" |
|
| 6 | 6 |
lncluster "github.com/docker/docker/libnetwork/cluster" |
| 7 | 7 |
) |
| 8 | 8 |
|
| ... | ... |
@@ -21,7 +21,7 @@ type ClusterStatus interface {
|
| 21 | 21 |
|
| 22 | 22 |
// NetworkManager provides methods to manage networks |
| 23 | 23 |
type NetworkManager interface {
|
| 24 |
- GetNetwork(input string) (apitypes.NetworkResource, error) |
|
| 25 |
- GetNetworks(filters.Args) ([]apitypes.NetworkResource, error) |
|
| 24 |
+ GetNetwork(input string) (network.Inspect, error) |
|
| 25 |
+ GetNetworks(filters.Args) ([]network.Inspect, error) |
|
| 26 | 26 |
RemoveNetwork(input string) error |
| 27 | 27 |
} |
| ... | ... |
@@ -137,7 +137,7 @@ func swarmPortConfigToAPIPortConfig(portConfig *swarmapi.PortConfig) types.PortC |
| 137 | 137 |
} |
| 138 | 138 |
|
| 139 | 139 |
// BasicNetworkFromGRPC converts a grpc Network to a NetworkResource. |
| 140 |
-func BasicNetworkFromGRPC(n swarmapi.Network) basictypes.NetworkResource {
|
|
| 140 |
+func BasicNetworkFromGRPC(n swarmapi.Network) networktypes.Inspect {
|
|
| 141 | 141 |
spec := n.Spec |
| 142 | 142 |
var ipam networktypes.IPAM |
| 143 | 143 |
if n.IPAM != nil {
|
| ... | ... |
@@ -157,7 +157,7 @@ func BasicNetworkFromGRPC(n swarmapi.Network) basictypes.NetworkResource {
|
| 157 | 157 |
} |
| 158 | 158 |
} |
| 159 | 159 |
|
| 160 |
- nr := basictypes.NetworkResource{
|
|
| 160 |
+ nr := networktypes.Inspect{
|
|
| 161 | 161 |
ID: n.ID, |
| 162 | 162 |
Name: n.Spec.Annotations.Name, |
| 163 | 163 |
Scope: scope.Swarm, |
| ... | ... |
@@ -19,7 +19,7 @@ import ( |
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 | 21 |
// GetNetworks returns all current cluster managed networks. |
| 22 |
-func (c *Cluster) GetNetworks(filter filters.Args) ([]apitypes.NetworkResource, error) {
|
|
| 22 |
+func (c *Cluster) GetNetworks(filter filters.Args) ([]network.Inspect, error) {
|
|
| 23 | 23 |
var f *swarmapi.ListNetworksRequest_Filters |
| 24 | 24 |
|
| 25 | 25 |
if filter.Len() > 0 {
|
| ... | ... |
@@ -44,13 +44,13 @@ func (c *Cluster) GetNetworks(filter filters.Args) ([]apitypes.NetworkResource, |
| 44 | 44 |
return internalnetwork.FilterNetworks(list, filter) |
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 |
-func filterPredefinedNetworks(networks *[]apitypes.NetworkResource) {
|
|
| 47 |
+func filterPredefinedNetworks(networks *[]network.Inspect) {
|
|
| 48 | 48 |
if networks == nil {
|
| 49 | 49 |
return |
| 50 | 50 |
} |
| 51 | 51 |
var idxs []int |
| 52 |
- for i, n := range *networks {
|
|
| 53 |
- if v, ok := n.Labels["com.docker.swarm.predefined"]; ok && v == "true" {
|
|
| 52 |
+ for i, nw := range *networks {
|
|
| 53 |
+ if v, ok := nw.Labels["com.docker.swarm.predefined"]; ok && v == "true" {
|
|
| 54 | 54 |
idxs = append(idxs, i) |
| 55 | 55 |
} |
| 56 | 56 |
} |
| ... | ... |
@@ -60,7 +60,7 @@ func filterPredefinedNetworks(networks *[]apitypes.NetworkResource) {
|
| 60 | 60 |
} |
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
-func (c *Cluster) getNetworks(filters *swarmapi.ListNetworksRequest_Filters) ([]apitypes.NetworkResource, error) {
|
|
| 63 |
+func (c *Cluster) getNetworks(filters *swarmapi.ListNetworksRequest_Filters) ([]network.Inspect, error) {
|
|
| 64 | 64 |
c.mu.RLock() |
| 65 | 65 |
defer c.mu.RUnlock() |
| 66 | 66 |
|
| ... | ... |
@@ -78,35 +78,35 @@ func (c *Cluster) getNetworks(filters *swarmapi.ListNetworksRequest_Filters) ([] |
| 78 | 78 |
return nil, err |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
- networks := make([]apitypes.NetworkResource, 0, len(r.Networks)) |
|
| 81 |
+ networks := make([]network.Inspect, 0, len(r.Networks)) |
|
| 82 | 82 |
|
| 83 |
- for _, network := range r.Networks {
|
|
| 84 |
- networks = append(networks, convert.BasicNetworkFromGRPC(*network)) |
|
| 83 |
+ for _, nw := range r.Networks {
|
|
| 84 |
+ networks = append(networks, convert.BasicNetworkFromGRPC(*nw)) |
|
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 | 87 |
return networks, nil |
| 88 | 88 |
} |
| 89 | 89 |
|
| 90 | 90 |
// GetNetwork returns a cluster network by an ID. |
| 91 |
-func (c *Cluster) GetNetwork(input string) (apitypes.NetworkResource, error) {
|
|
| 92 |
- var network *swarmapi.Network |
|
| 91 |
+func (c *Cluster) GetNetwork(input string) (network.Inspect, error) {
|
|
| 92 |
+ var nw *swarmapi.Network |
|
| 93 | 93 |
|
| 94 | 94 |
if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
| 95 | 95 |
n, err := getNetwork(ctx, state.controlClient, input) |
| 96 | 96 |
if err != nil {
|
| 97 | 97 |
return err |
| 98 | 98 |
} |
| 99 |
- network = n |
|
| 99 |
+ nw = n |
|
| 100 | 100 |
return nil |
| 101 | 101 |
}); err != nil {
|
| 102 |
- return apitypes.NetworkResource{}, err
|
|
| 102 |
+ return network.Inspect{}, err
|
|
| 103 | 103 |
} |
| 104 |
- return convert.BasicNetworkFromGRPC(*network), nil |
|
| 104 |
+ return convert.BasicNetworkFromGRPC(*nw), nil |
|
| 105 | 105 |
} |
| 106 | 106 |
|
| 107 | 107 |
// GetNetworksByName returns cluster managed networks by name. |
| 108 | 108 |
// It is ok to have multiple networks here. #18864 |
| 109 |
-func (c *Cluster) GetNetworksByName(name string) ([]apitypes.NetworkResource, error) {
|
|
| 109 |
+func (c *Cluster) GetNetworksByName(name string) ([]network.Inspect, error) {
|
|
| 110 | 110 |
// Note that swarmapi.GetNetworkRequest.Name is not functional. |
| 111 | 111 |
// So we cannot just use that with c.GetNetwork. |
| 112 | 112 |
return c.getNetworks(&swarmapi.ListNetworksRequest_Filters{
|
| ... | ... |
@@ -295,12 +295,12 @@ func (c *Cluster) CreateNetwork(s apitypes.NetworkCreateRequest) (string, error) |
| 295 | 295 |
// RemoveNetwork removes a cluster network. |
| 296 | 296 |
func (c *Cluster) RemoveNetwork(input string) error {
|
| 297 | 297 |
return c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
| 298 |
- network, err := getNetwork(ctx, state.controlClient, input) |
|
| 298 |
+ nw, err := getNetwork(ctx, state.controlClient, input) |
|
| 299 | 299 |
if err != nil {
|
| 300 | 300 |
return err |
| 301 | 301 |
} |
| 302 | 302 |
|
| 303 |
- _, err = state.controlClient.RemoveNetwork(ctx, &swarmapi.RemoveNetworkRequest{NetworkID: network.ID})
|
|
| 303 |
+ _, err = state.controlClient.RemoveNetwork(ctx, &swarmapi.RemoveNetworkRequest{NetworkID: nw.ID})
|
|
| 304 | 304 |
return err |
| 305 | 305 |
}) |
| 306 | 306 |
} |
| ... | ... |
@@ -312,10 +312,10 @@ func (c *Cluster) populateNetworkID(ctx context.Context, client swarmapi.Control |
| 312 | 312 |
if len(networks) == 0 {
|
| 313 | 313 |
networks = s.Networks //nolint:staticcheck // ignore SA1019: field is deprecated. |
| 314 | 314 |
} |
| 315 |
- for i, n := range networks {
|
|
| 316 |
- apiNetwork, err := getNetwork(ctx, client, n.Target) |
|
| 315 |
+ for i, nw := range networks {
|
|
| 316 |
+ apiNetwork, err := getNetwork(ctx, client, nw.Target) |
|
| 317 | 317 |
if err != nil {
|
| 318 |
- ln, _ := c.config.Backend.FindNetwork(n.Target) |
|
| 318 |
+ ln, _ := c.config.Backend.FindNetwork(nw.Target) |
|
| 319 | 319 |
if ln != nil && runconfig.IsPreDefinedNetwork(ln.Name()) {
|
| 320 | 320 |
// Need to retrieve the corresponding predefined swarm network |
| 321 | 321 |
// and use its id for the request. |
| ... | ... |
@@ -565,14 +565,14 @@ func (daemon *Daemon) deleteNetwork(nw *libnetwork.Network, dynamic bool) error |
| 565 | 565 |
} |
| 566 | 566 |
|
| 567 | 567 |
// GetNetworks returns a list of all networks |
| 568 |
-func (daemon *Daemon) GetNetworks(filter filters.Args, config backend.NetworkListConfig) (networks []types.NetworkResource, err error) {
|
|
| 568 |
+func (daemon *Daemon) GetNetworks(filter filters.Args, config backend.NetworkListConfig) (networks []network.Inspect, err error) {
|
|
| 569 | 569 |
var idx map[string]*libnetwork.Network |
| 570 | 570 |
if config.Detailed {
|
| 571 | 571 |
idx = make(map[string]*libnetwork.Network) |
| 572 | 572 |
} |
| 573 | 573 |
|
| 574 | 574 |
allNetworks := daemon.getAllNetworks() |
| 575 |
- networks = make([]types.NetworkResource, 0, len(allNetworks)) |
|
| 575 |
+ networks = make([]network.Inspect, 0, len(allNetworks)) |
|
| 576 | 576 |
for _, n := range allNetworks {
|
| 577 | 577 |
nr := buildNetworkResource(n) |
| 578 | 578 |
networks = append(networks, nr) |
| ... | ... |
@@ -600,12 +600,12 @@ func (daemon *Daemon) GetNetworks(filter filters.Args, config backend.NetworkLis |
| 600 | 600 |
|
| 601 | 601 |
// buildNetworkResource builds a [types.NetworkResource] from the given |
| 602 | 602 |
// [libnetwork.Network], to be returned by the API. |
| 603 |
-func buildNetworkResource(nw *libnetwork.Network) types.NetworkResource {
|
|
| 603 |
+func buildNetworkResource(nw *libnetwork.Network) network.Inspect {
|
|
| 604 | 604 |
if nw == nil {
|
| 605 |
- return types.NetworkResource{}
|
|
| 605 |
+ return network.Inspect{}
|
|
| 606 | 606 |
} |
| 607 | 607 |
|
| 608 |
- return types.NetworkResource{
|
|
| 608 |
+ return network.Inspect{
|
|
| 609 | 609 |
Name: nw.Name(), |
| 610 | 610 |
ID: nw.ID(), |
| 611 | 611 |
Created: nw.Created(), |
| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 | 1 |
package network // import "github.com/docker/docker/daemon/network" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "github.com/docker/docker/api/types" |
|
| 5 | 4 |
"github.com/docker/docker/api/types/filters" |
| 5 |
+ "github.com/docker/docker/api/types/network" |
|
| 6 | 6 |
"github.com/docker/docker/errdefs" |
| 7 | 7 |
"github.com/docker/docker/runconfig" |
| 8 | 8 |
"github.com/pkg/errors" |
| ... | ... |
@@ -10,7 +10,7 @@ import ( |
| 10 | 10 |
|
| 11 | 11 |
// FilterNetworks filters network list according to user specified filter |
| 12 | 12 |
// and returns user chosen networks |
| 13 |
-func FilterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.NetworkResource, error) {
|
|
| 13 |
+func FilterNetworks(nws []network.Inspect, filter filters.Args) ([]network.Inspect, error) {
|
|
| 14 | 14 |
// if filter is empty, return original network list |
| 15 | 15 |
if filter.Len() == 0 {
|
| 16 | 16 |
return nws, nil |
| ... | ... |
@@ -71,7 +71,7 @@ func FilterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.N |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 | 73 |
if filter.Contains("type") {
|
| 74 |
- typeNet := []types.NetworkResource{}
|
|
| 74 |
+ typeNet := []network.Inspect{}
|
|
| 75 | 75 |
errFilter := filter.WalkValues("type", func(fval string) error {
|
| 76 | 76 |
passList, err := filterNetworkByType(displayNet, fval) |
| 77 | 77 |
if err != nil {
|
| ... | ... |
@@ -89,10 +89,10 @@ func FilterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.N |
| 89 | 89 |
return displayNet, nil |
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 |
-func filterNetworkByUse(nws []types.NetworkResource, danglingOnly bool) []types.NetworkResource {
|
|
| 93 |
- retNws := []types.NetworkResource{}
|
|
| 92 |
+func filterNetworkByUse(nws []network.Inspect, danglingOnly bool) []network.Inspect {
|
|
| 93 |
+ retNws := []network.Inspect{}
|
|
| 94 | 94 |
|
| 95 |
- filterFunc := func(nw types.NetworkResource) bool {
|
|
| 95 |
+ filterFunc := func(nw network.Inspect) bool {
|
|
| 96 | 96 |
if danglingOnly {
|
| 97 | 97 |
return !runconfig.IsPreDefinedNetwork(nw.Name) && len(nw.Containers) == 0 && len(nw.Services) == 0 |
| 98 | 98 |
} |
| ... | ... |
@@ -108,8 +108,8 @@ func filterNetworkByUse(nws []types.NetworkResource, danglingOnly bool) []types. |
| 108 | 108 |
return retNws |
| 109 | 109 |
} |
| 110 | 110 |
|
| 111 |
-func filterNetworkByType(nws []types.NetworkResource, netType string) ([]types.NetworkResource, error) {
|
|
| 112 |
- retNws := []types.NetworkResource{}
|
|
| 111 |
+func filterNetworkByType(nws []network.Inspect, netType string) ([]network.Inspect, error) {
|
|
| 112 |
+ retNws := []network.Inspect{}
|
|
| 113 | 113 |
switch netType {
|
| 114 | 114 |
case "builtin": |
| 115 | 115 |
for _, nw := range nws {
|
| ... | ... |
@@ -6,13 +6,12 @@ import ( |
| 6 | 6 |
"strings" |
| 7 | 7 |
"testing" |
| 8 | 8 |
|
| 9 |
- "github.com/docker/docker/api/types" |
|
| 10 | 9 |
"github.com/docker/docker/api/types/filters" |
| 11 | 10 |
"github.com/docker/docker/api/types/network" |
| 12 | 11 |
) |
| 13 | 12 |
|
| 14 | 13 |
func TestFilterNetworks(t *testing.T) {
|
| 15 |
- networks := []types.NetworkResource{
|
|
| 14 |
+ networks := []network.Inspect{
|
|
| 16 | 15 |
{
|
| 17 | 16 |
Name: "host", |
| 18 | 17 |
Driver: "host", |
| ... | ... |
@@ -134,7 +133,7 @@ func TestFilterNetworks(t *testing.T) {
|
| 134 | 134 |
|
| 135 | 135 |
for _, testCase := range testCases {
|
| 136 | 136 |
t.Run(testCase.name, func(t *testing.T) {
|
| 137 |
- ls := make([]types.NetworkResource, 0, len(networks)) |
|
| 137 |
+ ls := make([]network.Inspect, 0, len(networks)) |
|
| 138 | 138 |
ls = append(ls, networks...) |
| 139 | 139 |
result, err := FilterNetworks(ls, testCase.filter) |
| 140 | 140 |
if testCase.err != "" {
|
| ... | ... |
@@ -218,7 +218,7 @@ func isNetworkAvailable(c *testing.T, name string) bool {
|
| 218 | 218 |
defer resp.Body.Close() |
| 219 | 219 |
assert.Equal(c, resp.StatusCode, http.StatusOK) |
| 220 | 220 |
|
| 221 |
- var nJSON []types.NetworkResource |
|
| 221 |
+ var nJSON []network.Inspect |
|
| 222 | 222 |
err = json.NewDecoder(body).Decode(&nJSON) |
| 223 | 223 |
assert.NilError(c, err) |
| 224 | 224 |
|
| ... | ... |
@@ -240,7 +240,7 @@ func getNetworkIDByName(c *testing.T, name string) string {
|
| 240 | 240 |
assert.Equal(c, resp.StatusCode, http.StatusOK) |
| 241 | 241 |
assert.NilError(c, err) |
| 242 | 242 |
|
| 243 |
- var nJSON []types.NetworkResource |
|
| 243 |
+ var nJSON []network.Inspect |
|
| 244 | 244 |
err = json.NewDecoder(body).Decode(&nJSON) |
| 245 | 245 |
assert.NilError(c, err) |
| 246 | 246 |
var res string |
| ... | ... |
@@ -255,11 +255,11 @@ func getNetworkIDByName(c *testing.T, name string) string {
|
| 255 | 255 |
return res |
| 256 | 256 |
} |
| 257 | 257 |
|
| 258 |
-func getNetworkResource(c *testing.T, id string) *types.NetworkResource {
|
|
| 258 |
+func getNetworkResource(c *testing.T, id string) *network.Inspect {
|
|
| 259 | 259 |
_, obj, err := request.Get(testutil.GetContext(c), "/networks/"+id) |
| 260 | 260 |
assert.NilError(c, err) |
| 261 | 261 |
|
| 262 |
- nr := types.NetworkResource{}
|
|
| 262 |
+ nr := network.Inspect{}
|
|
| 263 | 263 |
err = json.NewDecoder(obj).Decode(&nr) |
| 264 | 264 |
assert.NilError(c, err) |
| 265 | 265 |
|
| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
"time" |
| 16 | 16 |
|
| 17 | 17 |
"github.com/docker/docker/api/types" |
| 18 |
+ "github.com/docker/docker/api/types/network" |
|
| 18 | 19 |
"github.com/docker/docker/integration-cli/cli" |
| 19 | 20 |
"github.com/docker/docker/integration-cli/daemon" |
| 20 | 21 |
"github.com/docker/docker/libnetwork/driverapi" |
| ... | ... |
@@ -263,9 +264,9 @@ func assertNwList(c *testing.T, out string, expectNws []string) {
|
| 263 | 263 |
assert.DeepEqual(c, nwList, expectNws) |
| 264 | 264 |
} |
| 265 | 265 |
|
| 266 |
-func getNwResource(c *testing.T, name string) *types.NetworkResource {
|
|
| 266 |
+func getNwResource(c *testing.T, name string) *network.Inspect {
|
|
| 267 | 267 |
out := cli.DockerCmd(c, "network", "inspect", name).Stdout() |
| 268 |
- var nr []types.NetworkResource |
|
| 268 |
+ var nr []network.Inspect |
|
| 269 | 269 |
err := json.Unmarshal([]byte(out), &nr) |
| 270 | 270 |
assert.NilError(c, err) |
| 271 | 271 |
return &nr[0] |
| ... | ... |
@@ -418,7 +419,7 @@ func (s *DockerCLINetworkSuite) TestDockerNetworkDeleteMultiple(c *testing.T) {
|
| 418 | 418 |
|
| 419 | 419 |
func (s *DockerCLINetworkSuite) TestDockerNetworkInspect(c *testing.T) {
|
| 420 | 420 |
out := cli.DockerCmd(c, "network", "inspect", "host").Stdout() |
| 421 |
- var networkResources []types.NetworkResource |
|
| 421 |
+ var networkResources []network.Inspect |
|
| 422 | 422 |
err := json.Unmarshal([]byte(out), &networkResources) |
| 423 | 423 |
assert.NilError(c, err) |
| 424 | 424 |
assert.Equal(c, len(networkResources), 1) |
| ... | ... |
@@ -442,7 +443,7 @@ func (s *DockerCLINetworkSuite) TestDockerInspectMultipleNetwork(c *testing.T) {
|
| 442 | 442 |
result := dockerCmdWithResult("network", "inspect", "host", "none")
|
| 443 | 443 |
result.Assert(c, icmd.Success) |
| 444 | 444 |
|
| 445 |
- var networkResources []types.NetworkResource |
|
| 445 |
+ var networkResources []network.Inspect |
|
| 446 | 446 |
err := json.Unmarshal([]byte(result.Stdout()), &networkResources) |
| 447 | 447 |
assert.NilError(c, err) |
| 448 | 448 |
assert.Equal(c, len(networkResources), 2) |
| ... | ... |
@@ -458,7 +459,7 @@ func (s *DockerCLINetworkSuite) TestDockerInspectMultipleNetworksIncludingNonexi |
| 458 | 458 |
Out: "host", |
| 459 | 459 |
}) |
| 460 | 460 |
|
| 461 |
- var networkResources []types.NetworkResource |
|
| 461 |
+ var networkResources []network.Inspect |
|
| 462 | 462 |
err := json.Unmarshal([]byte(result.Stdout()), &networkResources) |
| 463 | 463 |
assert.NilError(c, err) |
| 464 | 464 |
assert.Equal(c, len(networkResources), 1) |
| ... | ... |
@@ -481,7 +482,7 @@ func (s *DockerCLINetworkSuite) TestDockerInspectMultipleNetworksIncludingNonexi |
| 481 | 481 |
Out: "host", |
| 482 | 482 |
}) |
| 483 | 483 |
|
| 484 |
- networkResources = []types.NetworkResource{}
|
|
| 484 |
+ networkResources = []network.Inspect{}
|
|
| 485 | 485 |
err = json.Unmarshal([]byte(result.Stdout()), &networkResources) |
| 486 | 486 |
assert.NilError(c, err) |
| 487 | 487 |
assert.Equal(c, len(networkResources), 1) |
| ... | ... |
@@ -504,7 +505,7 @@ func (s *DockerCLINetworkSuite) TestDockerInspectNetworkWithContainerName(c *tes |
| 504 | 504 |
}() |
| 505 | 505 |
|
| 506 | 506 |
out = cli.DockerCmd(c, "network", "inspect", "brNetForInspect").Stdout() |
| 507 |
- var networkResources []types.NetworkResource |
|
| 507 |
+ var networkResources []network.Inspect |
|
| 508 | 508 |
err := json.Unmarshal([]byte(out), &networkResources) |
| 509 | 509 |
assert.NilError(c, err) |
| 510 | 510 |
assert.Equal(c, len(networkResources), 1) |
| ... | ... |
@@ -518,7 +519,7 @@ func (s *DockerCLINetworkSuite) TestDockerInspectNetworkWithContainerName(c *tes |
| 518 | 518 |
|
| 519 | 519 |
// check whether network inspect works properly |
| 520 | 520 |
out = cli.DockerCmd(c, "network", "inspect", "brNetForInspect").Stdout() |
| 521 |
- var newNetRes []types.NetworkResource |
|
| 521 |
+ var newNetRes []network.Inspect |
|
| 522 | 522 |
err = json.Unmarshal([]byte(out), &newNetRes) |
| 523 | 523 |
assert.NilError(c, err) |
| 524 | 524 |
assert.Equal(c, len(newNetRes), 1) |
| ... | ... |
@@ -4,7 +4,6 @@ import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"testing" |
| 6 | 6 |
|
| 7 |
- "github.com/docker/docker/api/types" |
|
| 8 | 7 |
networktypes "github.com/docker/docker/api/types/network" |
| 9 | 8 |
dclient "github.com/docker/docker/client" |
| 10 | 9 |
"github.com/docker/docker/integration/internal/network" |
| ... | ... |
@@ -13,7 +12,7 @@ import ( |
| 13 | 13 |
"gotest.tools/v3/skip" |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 |
-func containsNetwork(nws []types.NetworkResource, networkID string) bool {
|
|
| 16 |
+func containsNetwork(nws []networktypes.Inspect, networkID string) bool {
|
|
| 17 | 17 |
for _, n := range nws {
|
| 18 | 18 |
if n.ID == networkID {
|
| 19 | 19 |
return true |
| ... | ... |
@@ -152,7 +152,7 @@ func TestNetworkList(t *testing.T) {
|
| 152 | 152 |
|
| 153 | 153 |
buf, err := request.ReadBody(body) |
| 154 | 154 |
assert.NilError(t, err) |
| 155 |
- var nws []types.NetworkResource |
|
| 155 |
+ var nws []ntypes.Inspect |
|
| 156 | 156 |
err = json.Unmarshal(buf, &nws) |
| 157 | 157 |
assert.NilError(t, err) |
| 158 | 158 |
assert.Assert(t, len(nws) > 0) |