Add IsPrivate method for NetworkMode

This method indicates that container using private network stack

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>
This commit is contained in:
Alexandr Morozov 2014-09-05 10:43:44 +04:00
Родитель b0cff06c97
Коммит 080ca86191
2 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -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)
}

Просмотреть файл

@ -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"
}