diff --git a/api/types/network/network.go b/api/types/network/network.go index 4be466fbf9..dc07cdf091 100644 --- a/api/types/network/network.go +++ b/api/types/network/network.go @@ -65,6 +65,16 @@ type ServiceInfo struct { Tasks []Task } +// EndpointResource contains network resources allocated and used for a +// container in a network. +type EndpointResource struct { + Name string + EndpointID string + MacAddress string + IPv4Address string + IPv6Address string +} + // NetworkingConfig represents the container's networking configuration for each of its interfaces // Carries the networking configs specified in the `docker run` and `docker network connect` commands type NetworkingConfig struct { diff --git a/api/types/types.go b/api/types/types.go index b5d1a1c14b..665150406c 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -425,32 +425,23 @@ type MountPoint struct { // NetworkResource is the body of the "get network" http response message type NetworkResource struct { - Name string // Name is the requested name of the network - ID string `json:"Id"` // ID uniquely identifies a network on a single machine - Created time.Time // Created is the time the network created - Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level) - Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`) - EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6 - IPAM network.IPAM // IPAM is the network's IP Address Management - Internal bool // Internal represents if the network is used internal only - Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. - Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. - ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. - 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. - Containers map[string]EndpointResource // Containers contains endpoints belonging to the network - Options map[string]string // Options holds the network specific options to use for when creating the network - Labels map[string]string // Labels holds metadata specific to the network being created - Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network - Services map[string]network.ServiceInfo `json:",omitempty"` -} - -// EndpointResource contains network resources allocated and used for a container in a network -type EndpointResource struct { - Name string - EndpointID string - MacAddress string - IPv4Address string - IPv6Address string + Name string // Name is the requested name of the network + ID string `json:"Id"` // ID uniquely identifies a network on a single machine + Created time.Time // Created is the time the network created + Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level) + Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`) + EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6 + IPAM network.IPAM // IPAM is the network's IP Address Management + Internal bool // Internal represents if the network is used internal only + Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. + Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. + ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. + 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. + Containers map[string]network.EndpointResource // Containers contains endpoints belonging to the network + Options map[string]string // Options holds the network specific options to use for when creating the network + Labels map[string]string // Labels holds metadata specific to the network being created + Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network + Services map[string]network.ServiceInfo `json:",omitempty"` } // NetworkCreate is the expected body of the "create network" http request message diff --git a/api/types/types_deprecated.go b/api/types/types_deprecated.go index 92d7591a88..433feb820d 100644 --- a/api/types/types_deprecated.go +++ b/api/types/types_deprecated.go @@ -54,3 +54,8 @@ type NetworkConnect = network.ConnectOptions // // Deprecated: use [network.DisconnectOptions]. type NetworkDisconnect = network.DisconnectOptions + +// EndpointResource contains network resources allocated and used for a container in a network. +// +// Deprecated: use [network.EndpointResource]. +type EndpointResource = network.EndpointResource diff --git a/daemon/network.go b/daemon/network.go index ba2b83e570..d0548ab424 100644 --- a/daemon/network.go +++ b/daemon/network.go @@ -618,7 +618,7 @@ func buildNetworkResource(nw *libnetwork.Network) types.NetworkResource { Ingress: nw.Ingress(), ConfigFrom: network.ConfigReference{Network: nw.ConfigFrom()}, ConfigOnly: nw.ConfigOnly(), - Containers: map[string]types.EndpointResource{}, + Containers: map[string]network.EndpointResource{}, Options: nw.DriverOptions(), Labels: nw.Labels(), Peers: buildPeerInfoResources(nw.Peers()), @@ -628,8 +628,8 @@ func buildNetworkResource(nw *libnetwork.Network) types.NetworkResource { // buildContainerAttachments creates a [types.EndpointResource] map of all // containers attached to the network. It is used when listing networks in // detailed mode. -func buildContainerAttachments(nw *libnetwork.Network) map[string]types.EndpointResource { - containers := make(map[string]types.EndpointResource) +func buildContainerAttachments(nw *libnetwork.Network) map[string]network.EndpointResource { + containers := make(map[string]network.EndpointResource) for _, e := range nw.Endpoints() { ei := e.Info() if ei == nil { @@ -754,8 +754,8 @@ func buildIPAMResources(nw *libnetwork.Network) network.IPAM { // buildEndpointResource combines information from the endpoint and additional // endpoint-info into a [types.EndpointResource]. -func buildEndpointResource(ep *libnetwork.Endpoint, info libnetwork.EndpointInfo) types.EndpointResource { - er := types.EndpointResource{ +func buildEndpointResource(ep *libnetwork.Endpoint, info libnetwork.EndpointInfo) network.EndpointResource { + er := network.EndpointResource{ EndpointID: ep.ID(), Name: ep.Name(), } diff --git a/daemon/network/filter_test.go b/daemon/network/filter_test.go index 7fdd9dc2e4..b272fed588 100644 --- a/daemon/network/filter_test.go +++ b/daemon/network/filter_test.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/network" ) func TestFilterNetworks(t *testing.T) { @@ -46,7 +47,7 @@ func TestFilterNetworks(t *testing.T) { Name: "networkwithcontainer", Driver: "nwc", Scope: "local", - Containers: map[string]types.EndpointResource{ + Containers: map[string]network.EndpointResource{ "customcontainer": { Name: "customendpoint", },