mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move DisconnectFromNetwork back to daemon/
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
6bb0d1816a
commit
5bb4d0d9ea
5 changed files with 63 additions and 66 deletions
|
@ -20,7 +20,6 @@ import (
|
|||
"github.com/docker/docker/pkg/nat"
|
||||
"github.com/docker/docker/pkg/symlink"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/docker/libnetwork"
|
||||
|
@ -374,64 +373,6 @@ func (container *Container) SetupWorkingDirectory() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// DisconnectFromNetwork disconnects a container from a network
|
||||
func (container *Container) DisconnectFromNetwork(n libnetwork.Network) error {
|
||||
if !container.Running {
|
||||
return derr.ErrorCodeNotRunning.WithArgs(container.ID)
|
||||
}
|
||||
|
||||
if container.HostConfig.NetworkMode.IsHost() && runconfig.NetworkMode(n.Type()).IsHost() {
|
||||
return runconfig.ErrConflictHostNetwork
|
||||
}
|
||||
|
||||
if err := container.disconnectFromNetwork(n); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.ToDiskLocking(); err != nil {
|
||||
return fmt.Errorf("Error saving container to disk: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (container *Container) disconnectFromNetwork(n libnetwork.Network) error {
|
||||
var (
|
||||
ep libnetwork.Endpoint
|
||||
sbox libnetwork.Sandbox
|
||||
)
|
||||
|
||||
s := func(current libnetwork.Endpoint) bool {
|
||||
epInfo := current.Info()
|
||||
if epInfo == nil {
|
||||
return false
|
||||
}
|
||||
if sb := epInfo.Sandbox(); sb != nil {
|
||||
if sb.ContainerID() == container.ID {
|
||||
ep = current
|
||||
sbox = sb
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
n.WalkEndpoints(s)
|
||||
|
||||
if ep == nil {
|
||||
return fmt.Errorf("container %s is not connected to the network", container.ID)
|
||||
}
|
||||
|
||||
if err := ep.Leave(sbox); err != nil {
|
||||
return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err)
|
||||
}
|
||||
|
||||
if err := ep.Delete(); err != nil {
|
||||
return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err)
|
||||
}
|
||||
|
||||
delete(container.NetworkSettings.Networks, n.Name())
|
||||
return nil
|
||||
}
|
||||
|
||||
// appendNetworkMounts appends any network mounts to the array of mount points passed in
|
||||
func appendNetworkMounts(container *Container, volumeMounts []volume.MountPoint) ([]volume.MountPoint, error) {
|
||||
for _, mnt := range container.NetworkMounts() {
|
||||
|
|
|
@ -5,7 +5,6 @@ package container
|
|||
import (
|
||||
"github.com/docker/docker/daemon/execdriver"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/docker/libnetwork"
|
||||
)
|
||||
|
||||
// DefaultPathEnv is deliberately empty on Windows as the default path will be set by
|
||||
|
@ -26,11 +25,6 @@ func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string
|
|||
return container.Config.Env
|
||||
}
|
||||
|
||||
// DisconnectFromNetwork disconnects a container from the network.
|
||||
func (container *Container) DisconnectFromNetwork(n libnetwork.Network) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetupWorkingDirectory initializes the container working directory.
|
||||
// This is a NOOP In windows.
|
||||
func (container *Container) SetupWorkingDirectory() error {
|
||||
|
|
|
@ -657,6 +657,62 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
|
|||
return nil
|
||||
}
|
||||
|
||||
// DisconnectFromNetwork disconnects container from network n.
|
||||
func (daemon *Daemon) DisconnectFromNetwork(container *container.Container, n libnetwork.Network) error {
|
||||
if !container.Running {
|
||||
return derr.ErrorCodeNotRunning.WithArgs(container.ID)
|
||||
}
|
||||
|
||||
if container.HostConfig.NetworkMode.IsHost() && runconfig.NetworkMode(n.Type()).IsHost() {
|
||||
return runconfig.ErrConflictHostNetwork
|
||||
}
|
||||
|
||||
return disconnectFromNetwork(container, n)
|
||||
}
|
||||
|
||||
func disconnectFromNetwork(container *container.Container, n libnetwork.Network) error {
|
||||
|
||||
if err := container.ToDiskLocking(); err != nil {
|
||||
return fmt.Errorf("Error saving container to disk: %v", err)
|
||||
}
|
||||
|
||||
var (
|
||||
ep libnetwork.Endpoint
|
||||
sbox libnetwork.Sandbox
|
||||
)
|
||||
|
||||
s := func(current libnetwork.Endpoint) bool {
|
||||
epInfo := current.Info()
|
||||
if epInfo == nil {
|
||||
return false
|
||||
}
|
||||
if sb := epInfo.Sandbox(); sb != nil {
|
||||
if sb.ContainerID() == container.ID {
|
||||
ep = current
|
||||
sbox = sb
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
n.WalkEndpoints(s)
|
||||
|
||||
if ep == nil {
|
||||
return fmt.Errorf("container %s is not connected to the network", container.ID)
|
||||
}
|
||||
|
||||
if err := ep.Leave(sbox); err != nil {
|
||||
return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err)
|
||||
}
|
||||
|
||||
if err := ep.Delete(); err != nil {
|
||||
return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err)
|
||||
}
|
||||
|
||||
delete(container.NetworkSettings.Networks, n.Name())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) initializeNetworking(container *container.Container) error {
|
||||
var err error
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/docker/docker/daemon/execdriver"
|
||||
derr "github.com/docker/docker/errors"
|
||||
"github.com/docker/docker/layer"
|
||||
"github.com/docker/libnetwork"
|
||||
)
|
||||
|
||||
func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]string, error) {
|
||||
|
@ -24,6 +25,11 @@ func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName
|
|||
return nil
|
||||
}
|
||||
|
||||
// DisconnectFromNetwork disconnects a container from the network.
|
||||
func (daemon *Daemon) DisconnectFromNetwork(container *container.Container, n libnetwork.Network) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) populateCommand(c *container.Container, env []string) error {
|
||||
en := &execdriver.Network{
|
||||
Interface: nil,
|
||||
|
|
|
@ -144,7 +144,7 @@ func (daemon *Daemon) DisconnectContainerFromNetwork(containerName string, netwo
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return container.DisconnectFromNetwork(network)
|
||||
return daemon.DisconnectFromNetwork(container, network)
|
||||
}
|
||||
|
||||
// GetNetworkDriverList returns the list of plugins drivers
|
||||
|
|
Loading…
Reference in a new issue