1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #30673 from mavenugo/nr

List Networks need not pull all the endpoints
This commit is contained in:
Tibor Vass 2017-02-03 19:09:43 -08:00 committed by GitHub
commit 4dbc105fc1
2 changed files with 25 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/versions"
"github.com/docker/libnetwork" "github.com/docker/libnetwork"
"github.com/docker/libnetwork/networkdb" "github.com/docker/libnetwork/networkdb"
) )
@ -55,7 +56,18 @@ SKIP:
continue SKIP continue SKIP
} }
} }
list = append(list, *n.buildNetworkResource(nw))
var nr *types.NetworkResource
// Versions < 1.26 fetches all the containers attached to a network
// in a network list api call. It is a heavy weight operation when
// run across all the networks. Starting API version 1.26, this detailed
// info is available for network specific GET API (equivalent to inspect)
if versions.LessThan(httputils.VersionFromContext(ctx), "1.26") {
nr = n.buildDetailedNetworkResources(nw)
} else {
nr = n.buildNetworkResource(nw)
}
list = append(list, *nr)
} }
list, err = filterNetworks(list, netFilters) list, err = filterNetworks(list, netFilters)
@ -77,7 +89,7 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r
} }
return err return err
} }
return httputils.WriteJSON(w, http.StatusOK, n.buildNetworkResource(nw)) return httputils.WriteJSON(w, http.StatusOK, n.buildDetailedNetworkResources(nw))
} }
func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
@ -198,6 +210,15 @@ func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.Netwo
r.Peers = buildPeerInfoResources(peers) r.Peers = buildPeerInfoResources(peers)
} }
return r
}
func (n *networkRouter) buildDetailedNetworkResources(nw libnetwork.Network) *types.NetworkResource {
if nw == nil {
return &types.NetworkResource{}
}
r := n.buildNetworkResource(nw)
epl := nw.Endpoints() epl := nw.Endpoints()
for _, e := range epl { for _, e := range epl {
ei := e.Info() ei := e.Info()

View file

@ -17,8 +17,8 @@ keywords: "API, Docker, rcli, REST, documentation"
[Docker Engine API v1.26](v1.26/) documentation [Docker Engine API v1.26](v1.26/) documentation
* `GET /containers/(id or name)/attach/ws` now returns WebSocket in binary frame format for API version >= v1.26, * `GET /containers/(id or name)/attach/ws` now returns WebSocket in binary frame format for API version >= v1.26, and returns WebSocket in text frame format for API version< v1.26, for the purpose of backward-compatibility.
and returns WebSocket in text frame format for API version< v1.26, for the purpose of backward-compatibility. * `GET /networks` is optimised only to return list of all networks and network specific information. List of all containers attached to a specific network is removed from this API and is only available using the network specific `GET /networks/{network-id}.
## v1.25 API changes ## v1.25 API changes