X Tutup
Skip to content

Commit 5bfefb2

Browse files
committed
Changing the get network request to return swarm scope predefined networks
Starting 17.06 swarm service create supports service creates with predefined networks like host and bridge. Due to the nature of the feature, swarm manager has a swarm scope predefined networks in addition to local scoped predefined networks on all nodes. However network inspects for swarm scoped predefined networks was not possible. The fix adds support for network inspect for swarm scoped predefined networks. Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
1 parent 2f8a3af commit 5bfefb2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

api/server/router/network/network_routes.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/docker/docker/api/types/network"
1717
"github.com/docker/docker/api/types/versions"
1818
"github.com/docker/libnetwork"
19+
netconst "github.com/docker/libnetwork/datastore"
1920
"github.com/docker/libnetwork/networkdb"
2021
)
2122

@@ -135,6 +136,17 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r
135136
}
136137
}
137138

139+
nwk, err := n.cluster.GetNetwork(term)
140+
if err == nil {
141+
// If the get network is passed with a specific network ID / partial network ID
142+
// or if the get network was passed with a network name and scope as swarm
143+
// return the network. Skipped using isMatchingScope because it is true if the scope
144+
// is not set which would be case if the client API v1.30
145+
if strings.HasPrefix(nwk.ID, term) || (netconst.SwarmScope == scope) {
146+
return httputils.WriteJSON(w, http.StatusOK, nwk)
147+
}
148+
}
149+
138150
nr, _ := n.cluster.GetNetworks()
139151
for _, network := range nr {
140152
if network.ID == term && isMatchingScope(network.Scope, scope) {

0 commit comments

Comments
 (0)
X Tutup