diff options
author | Madhu Venugopal <madhu@docker.com> | 2016-06-12 21:29:26 -0700 |
---|---|---|
committer | Tonis Tiigi <tonistiigi@gmail.com> | 2016-06-13 18:22:35 -0700 |
commit | 6e0bbc1f149c56a79076fd54553bbe8d10c6a383 (patch) | |
tree | 8b3c5e97a5634dda55febb5389889b792cb1b027 | |
parent | 7030903a9755ae22f3d4f1e74b1fbcf9dfe36ee2 (diff) | |
download | docker-6e0bbc1f149c56a79076fd54553bbe8d10c6a383.tar.gz |
swarm managed networks should me marked as "swarm" scoped (backend)
Signed-off-by: Madhu Venugopal <madhu@docker.com>
-rw-r--r-- | api/server/router/network/network_routes.go | 35 | ||||
-rw-r--r-- | daemon/cluster/convert/network.go | 3 |
2 files changed, 22 insertions, 16 deletions
diff --git a/api/server/router/network/network_routes.go b/api/server/router/network/network_routes.go index 795188f1f9..7e5b94cb91 100644 --- a/api/server/router/network/network_routes.go +++ b/api/server/router/network/network_routes.go @@ -26,24 +26,24 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit list := []types.NetworkResource{} - for _, nw := range n.backend.GetNetworks() { - list = append(list, *buildNetworkResource(nw)) - } - - // Combine the network list returned by the cluster manager if it is not already - // returned by the daemon backend if nr, err := n.clusterProvider.GetNetworks(); err == nil { - SKIP: for _, nw := range nr { - for _, nl := range list { - if nl.ID == nw.ID { - continue SKIP - } - } list = append(list, nw) } } + // Combine the network list returned by Docker daemon if it is not already + // returned by the cluster manager +SKIP: + for _, nw := range n.backend.GetNetworks() { + for _, nl := range list { + if nl.ID == nw.ID() { + continue SKIP + } + } + list = append(list, *n.buildNetworkResource(nw)) + } + list, err = filterNetworks(list, netFilters) if err != nil { return err @@ -63,7 +63,7 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r } return err } - return httputils.WriteJSON(w, http.StatusOK, buildNetworkResource(nw)) + return httputils.WriteJSON(w, http.StatusOK, n.buildNetworkResource(nw)) } func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { @@ -154,7 +154,7 @@ func (n *networkRouter) deleteNetwork(ctx context.Context, w http.ResponseWriter return nil } -func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource { +func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.NetworkResource { r := &types.NetworkResource{} if nw == nil { return r @@ -164,6 +164,13 @@ func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource { r.Name = nw.Name() r.ID = nw.ID() r.Scope = info.Scope() + if n.clusterProvider.IsManager() { + if _, err := n.clusterProvider.GetNetwork(nw.Name()); err == nil { + r.Scope = "swarm" + } + } else if info.Dynamic() { + r.Scope = "swarm" + } r.Driver = nw.Type() r.EnableIPv6 = info.IPv6Enabled() r.Internal = info.Internal() diff --git a/daemon/cluster/convert/network.go b/daemon/cluster/convert/network.go index 535886ef67..712f2724c5 100644 --- a/daemon/cluster/convert/network.go +++ b/daemon/cluster/convert/network.go @@ -6,7 +6,6 @@ import ( basictypes "github.com/docker/engine-api/types" networktypes "github.com/docker/engine-api/types/network" types "github.com/docker/engine-api/types/swarm" - "github.com/docker/libnetwork/datastore" swarmapi "github.com/docker/swarmkit/api" "github.com/docker/swarmkit/protobuf/ptypes" ) @@ -153,7 +152,7 @@ func BasicNetworkFromGRPC(n swarmapi.Network) basictypes.NetworkResource { return basictypes.NetworkResource{ ID: n.ID, Name: n.Spec.Annotations.Name, - Scope: datastore.GlobalScope, + Scope: "swarm", Driver: n.DriverState.Name, EnableIPv6: spec.Ipv6Enabled, IPAM: ipam, |