Browse code

Add IsPrivate method for NetworkMode

This method indicates that container using private network stack

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>

Alexandr Morozov authored on 2014/09/05 15:43:44
Showing 2 changed files
... ...
@@ -434,7 +434,7 @@ func (container *Container) buildHostnameAndHostsFiles(IP string) error {
434 434
 
435 435
 func (container *Container) allocateNetwork() error {
436 436
 	mode := container.hostConfig.NetworkMode
437
-	if container.Config.NetworkDisabled || mode.IsContainer() || mode.IsHost() || mode.IsNone() {
437
+	if container.Config.NetworkDisabled || !mode.IsPrivate() {
438 438
 		return nil
439 439
 	}
440 440
 
... ...
@@ -905,7 +905,7 @@ func (container *Container) updateParentsHosts() error {
905 905
 		}
906 906
 
907 907
 		c := container.daemon.Get(cid)
908
-		if c != nil && !container.daemon.config.DisableNetwork && !container.hostConfig.NetworkMode.IsContainer() && !container.hostConfig.NetworkMode.IsHost() {
908
+		if c != nil && !container.daemon.config.DisableNetwork && container.hostConfig.NetworkMode.IsPrivate() {
909 909
 			if err := etchosts.Update(c.HostsPath, container.NetworkSettings.IPAddress, container.Name[1:]); err != nil {
910 910
 				return fmt.Errorf("Failed to update /etc/hosts in parent container: %v", err)
911 911
 			}
... ...
@@ -10,6 +10,11 @@ import (
10 10
 
11 11
 type NetworkMode string
12 12
 
13
+// IsPrivate indicates whether container use it's private network stack
14
+func (n NetworkMode) IsPrivate() bool {
15
+	return !(n.IsHost() || n.IsContainer() || n.IsNone())
16
+}
17
+
13 18
 func (n NetworkMode) IsHost() bool {
14 19
 	return n == "host"
15 20
 }