Browse code

Fixed a few network UI issues in swarm-mode

* Detect name conflicts on network creation
* Detect and prevent network connect/disconnect for managed containers

Signed-off-by: Madhu Venugopal <madhu@docker.com>

Madhu Venugopal authored on 2016/06/30 10:08:55
Showing 2 changed files
... ...
@@ -81,6 +81,10 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
81 81
 		return err
82 82
 	}
83 83
 
84
+	if _, err := n.clusterProvider.GetNetwork(create.Name); err == nil {
85
+		return libnetwork.NetworkNameError(create.Name)
86
+	}
87
+
84 88
 	nw, err := n.backend.CreateNetwork(create)
85 89
 	if err != nil {
86 90
 		if _, ok := err.(libnetwork.ManagerRedirectError); !ok {
... ...
@@ -292,6 +292,10 @@ func (daemon *Daemon) UpdateContainerServiceConfig(containerName string, service
292 292
 	return nil
293 293
 }
294 294
 
295
+func errClusterNetworkConnect() error {
296
+	return fmt.Errorf("cannot connect or disconnect managed containers on a network")
297
+}
298
+
295 299
 // ConnectContainerToNetwork connects the given container to the given
296 300
 // network. If either cannot be found, an err is returned. If the
297 301
 // network cannot be set up, an err is returned.
... ...
@@ -300,6 +304,9 @@ func (daemon *Daemon) ConnectContainerToNetwork(containerName, networkName strin
300 300
 	if err != nil {
301 301
 		return err
302 302
 	}
303
+	if container.Managed {
304
+		return errClusterNetworkConnect()
305
+	}
303 306
 	return daemon.ConnectToNetwork(container, networkName, endpointConfig)
304 307
 }
305 308
 
... ...
@@ -313,6 +320,9 @@ func (daemon *Daemon) DisconnectContainerFromNetwork(containerName string, netwo
313 313
 		}
314 314
 		return err
315 315
 	}
316
+	if container.Managed {
317
+		return errClusterNetworkConnect()
318
+	}
316 319
 	return daemon.DisconnectFromNetwork(container, network, force)
317 320
 }
318 321