From fcafc7108b7b7f2ca9c2982b29b47de424f2da52 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Mon, 1 May 2017 14:44:05 -0700 Subject: [PATCH] Allow to control network scope - User can now promote a network's scope to swarm, so that the network is visible to swarm Signed-off-by: Alessandro Boch --- api/server/router/network/network_routes.go | 7 ------- api/types/types.go | 3 ++- daemon/network.go | 1 + 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/api/server/router/network/network_routes.go b/api/server/router/network/network_routes.go index e162ca92ac..05faffddb1 100644 --- a/api/server/router/network/network_routes.go +++ b/api/server/router/network/network_routes.go @@ -283,13 +283,6 @@ func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.Netwo r.ID = nw.ID() r.Created = info.Created() r.Scope = info.Scope() - if n.cluster.IsManager() { - if _, err := n.cluster.GetNetwork(nw.ID()); 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/api/types/types.go b/api/types/types.go index fa205e1114..fa9f1b0de1 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -396,7 +396,7 @@ 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. `global` for cluster-wide or `local` for machine level) + 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 @@ -432,6 +432,7 @@ type NetworkCreate struct { // which has the same name but it is not guaranteed to catch all name collisions. CheckDuplicate bool Driver string + Scope string EnableIPv6 bool IPAM *network.IPAM Internal bool diff --git a/daemon/network.go b/daemon/network.go index 6c026f160b..ca8d37f416 100644 --- a/daemon/network.go +++ b/daemon/network.go @@ -318,6 +318,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string libnetwork.NetworkOptionLabels(create.Labels), libnetwork.NetworkOptionAttachable(create.Attachable), libnetwork.NetworkOptionIngress(create.Ingress), + libnetwork.NetworkOptionScope(create.Scope), } if create.ConfigOnly {