github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/runconfig/hostconfig_unix.go (about)

     1  // +build !windows
     2  
     3  package runconfig
     4  
     5  import (
     6  	"strings"
     7  )
     8  
     9  // IsPrivate indicates whether container uses it's private network stack.
    10  func (n NetworkMode) IsPrivate() bool {
    11  	return !(n.IsHost() || n.IsContainer())
    12  }
    13  
    14  // IsDefault indicates whether container uses the default network stack.
    15  func (n NetworkMode) IsDefault() bool {
    16  	return n == "default"
    17  }
    18  
    19  // DefaultDaemonNetworkMode returns the default network stack the daemon should
    20  // use.
    21  func DefaultDaemonNetworkMode() NetworkMode {
    22  	return NetworkMode("bridge")
    23  }
    24  
    25  // NetworkName returns the name of the network stack.
    26  func (n NetworkMode) NetworkName() string {
    27  	if n.IsBridge() {
    28  		return "bridge"
    29  	} else if n.IsHost() {
    30  		return "host"
    31  	} else if n.IsContainer() {
    32  		return "container"
    33  	} else if n.IsNone() {
    34  		return "none"
    35  	} else if n.IsDefault() {
    36  		return "default"
    37  	}
    38  	return ""
    39  }
    40  
    41  // IsBridge indicates whether container uses the bridge network stack
    42  func (n NetworkMode) IsBridge() bool {
    43  	return n == "bridge"
    44  }
    45  
    46  // IsHost indicates whether container uses the host network stack.
    47  func (n NetworkMode) IsHost() bool {
    48  	return n == "host"
    49  }
    50  
    51  // IsContainer indicates whether container uses a container network stack.
    52  func (n NetworkMode) IsContainer() bool {
    53  	parts := strings.SplitN(string(n), ":", 2)
    54  	return len(parts) > 1 && parts[0] == "container"
    55  }
    56  
    57  // IsNone indicates whether container isn't using a network stack.
    58  func (n NetworkMode) IsNone() bool {
    59  	return n == "none"
    60  }
    61  
    62  // MergeConfigs merges the specified container Config and HostConfig.
    63  // It creates a ContainerConfigWrapper.
    64  func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper {
    65  	return &ContainerConfigWrapper{
    66  		config,
    67  		hostConfig,
    68  		"", nil,
    69  	}
    70  }