Skip to content

Commit

Permalink
Fixed a few network UI issues in swarm-mode
Browse files Browse the repository at this point in the history
* Detect name conflicts on network creation
* Detect and prevent network connect/disconnect for managed containers

Signed-off-by: Madhu Venugopal <[email protected]>
  • Loading branch information
mavenugo committed Jun 30, 2016
1 parent e904f58 commit 0ce5158
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/server/router/network/network_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
return err
}

if _, err := n.clusterProvider.GetNetwork(create.Name); err == nil {
return libnetwork.NetworkNameError(create.Name)
}

nw, err := n.backend.CreateNetwork(create)
if err != nil {
if _, ok := err.(libnetwork.ManagerRedirectError); !ok {
Expand Down
10 changes: 10 additions & 0 deletions daemon/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ func (daemon *Daemon) UpdateContainerServiceConfig(containerName string, service
return nil
}

func errClusterNetworkConnect() error {
return fmt.Errorf("cannot connect or disconnect managed containers on a network")
}

// ConnectContainerToNetwork connects the given container to the given
// network. If either cannot be found, an err is returned. If the
// network cannot be set up, an err is returned.
Expand All @@ -300,6 +304,9 @@ func (daemon *Daemon) ConnectContainerToNetwork(containerName, networkName strin
if err != nil {
return err
}
if container.Managed {
return errClusterNetworkConnect()
}
return daemon.ConnectToNetwork(container, networkName, endpointConfig)
}

Expand All @@ -313,6 +320,9 @@ func (daemon *Daemon) DisconnectContainerFromNetwork(containerName string, netwo
}
return err
}
if container.Managed {
return errClusterNetworkConnect()
}
return daemon.DisconnectFromNetwork(container, network, force)
}

Expand Down

0 comments on commit 0ce5158

Please sign in to comment.