From 080ca8619172b020c7da29b46f2fe4c939bb47ca Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Fri, 5 Sep 2014 10:43:44 +0400 Subject: [PATCH] Add IsPrivate method for NetworkMode This method indicates that container using private network stack Signed-off-by: Alexandr Morozov --- daemon/container.go | 4 ++-- runconfig/hostconfig.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index f63bbe6370..1878e99176 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -434,7 +434,7 @@ func (container *Container) buildHostnameAndHostsFiles(IP string) error { func (container *Container) allocateNetwork() error { mode := container.hostConfig.NetworkMode - if container.Config.NetworkDisabled || mode.IsContainer() || mode.IsHost() || mode.IsNone() { + if container.Config.NetworkDisabled || !mode.IsPrivate() { return nil } @@ -905,7 +905,7 @@ func (container *Container) updateParentsHosts() error { } c := container.daemon.Get(cid) - if c != nil && !container.daemon.config.DisableNetwork && !container.hostConfig.NetworkMode.IsContainer() && !container.hostConfig.NetworkMode.IsHost() { + if c != nil && !container.daemon.config.DisableNetwork && container.hostConfig.NetworkMode.IsPrivate() { if err := etchosts.Update(c.HostsPath, container.NetworkSettings.IPAddress, container.Name[1:]); err != nil { return fmt.Errorf("Failed to update /etc/hosts in parent container: %v", err) } diff --git a/runconfig/hostconfig.go b/runconfig/hostconfig.go index cd72a1517e..2c6b9feb9f 100644 --- a/runconfig/hostconfig.go +++ b/runconfig/hostconfig.go @@ -10,6 +10,11 @@ import ( type NetworkMode string +// IsPrivate indicates whether container use it's private network stack +func (n NetworkMode) IsPrivate() bool { + return !(n.IsHost() || n.IsContainer() || n.IsNone()) +} + func (n NetworkMode) IsHost() bool { return n == "host" }