Browse code

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 <aboch@docker.com>

Alessandro Boch authored on 2017/05/02 06:44:05
Showing 3 changed files
... ...
@@ -283,13 +283,6 @@ func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.Netwo
283 283
 	r.ID = nw.ID()
284 284
 	r.Created = info.Created()
285 285
 	r.Scope = info.Scope()
286
-	if n.cluster.IsManager() {
287
-		if _, err := n.cluster.GetNetwork(nw.ID()); err == nil {
288
-			r.Scope = "swarm"
289
-		}
290
-	} else if info.Dynamic() {
291
-		r.Scope = "swarm"
292
-	}
293 286
 	r.Driver = nw.Type()
294 287
 	r.EnableIPv6 = info.IPv6Enabled()
295 288
 	r.Internal = info.Internal()
... ...
@@ -396,7 +396,7 @@ type NetworkResource struct {
396 396
 	Name       string                         // Name is the requested name of the network
397 397
 	ID         string                         `json:"Id"` // ID uniquely identifies a network on a single machine
398 398
 	Created    time.Time                      // Created is the time the network created
399
-	Scope      string                         // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level)
399
+	Scope      string                         // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
400 400
 	Driver     string                         // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
401 401
 	EnableIPv6 bool                           // EnableIPv6 represents whether to enable IPv6
402 402
 	IPAM       network.IPAM                   // IPAM is the network's IP Address Management
... ...
@@ -432,6 +432,7 @@ type NetworkCreate struct {
432 432
 	// which has the same name but it is not guaranteed to catch all name collisions.
433 433
 	CheckDuplicate bool
434 434
 	Driver         string
435
+	Scope          string
435 436
 	EnableIPv6     bool
436 437
 	IPAM           *network.IPAM
437 438
 	Internal       bool
... ...
@@ -318,6 +318,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
318 318
 		libnetwork.NetworkOptionLabels(create.Labels),
319 319
 		libnetwork.NetworkOptionAttachable(create.Attachable),
320 320
 		libnetwork.NetworkOptionIngress(create.Ingress),
321
+		libnetwork.NetworkOptionScope(create.Scope),
321 322
 	}
322 323
 
323 324
 	if create.ConfigOnly {