github.com/fntlnz/docker@v1.9.0-rc3/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  	} else if n.IsUserDefined() {
    38  		return n.UserDefined()
    39  	}
    40  	return ""
    41  }
    42  
    43  // IsBridge indicates whether container uses the bridge network stack
    44  func (n NetworkMode) IsBridge() bool {
    45  	return n == "bridge"
    46  }
    47  
    48  // IsHost indicates whether container uses the host network stack.
    49  func (n NetworkMode) IsHost() bool {
    50  	return n == "host"
    51  }
    52  
    53  // IsContainer indicates whether container uses a container network stack.
    54  func (n NetworkMode) IsContainer() bool {
    55  	parts := strings.SplitN(string(n), ":", 2)
    56  	return len(parts) > 1 && parts[0] == "container"
    57  }
    58  
    59  // IsNone indicates whether container isn't using a network stack.
    60  func (n NetworkMode) IsNone() bool {
    61  	return n == "none"
    62  }
    63  
    64  // IsUserDefined indicates user-created network
    65  func (n NetworkMode) IsUserDefined() bool {
    66  	return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer()
    67  }
    68  
    69  //UserDefined indicates user-created network
    70  func (n NetworkMode) UserDefined() string {
    71  	if n.IsUserDefined() {
    72  		return string(n)
    73  	}
    74  	return ""
    75  }
    76  
    77  // MergeConfigs merges the specified container Config and HostConfig.
    78  // It creates a ContainerConfigWrapper.
    79  func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper {
    80  	return &ContainerConfigWrapper{
    81  		config,
    82  		hostConfig,
    83  		"", nil,
    84  	}
    85  }