2015-06-23 13:13:42 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// IsPrivate indicates whether container uses it's private network stack.
|
2015-06-23 13:13:42 -04:00
|
|
|
func (n NetworkMode) IsPrivate() bool {
|
|
|
|
return !(n.IsHost() || n.IsContainer())
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// IsDefault indicates whether container uses the default network stack.
|
2015-06-23 13:13:42 -04:00
|
|
|
func (n NetworkMode) IsDefault() bool {
|
|
|
|
return n == "default"
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// DefaultDaemonNetworkMode returns the default network stack the daemon should
|
|
|
|
// use.
|
2015-06-23 13:13:42 -04:00
|
|
|
func DefaultDaemonNetworkMode() NetworkMode {
|
|
|
|
return NetworkMode("bridge")
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// NetworkName returns the name of the network stack.
|
2015-06-23 13:13:42 -04:00
|
|
|
func (n NetworkMode) NetworkName() string {
|
|
|
|
if n.IsBridge() {
|
|
|
|
return "bridge"
|
|
|
|
} else if n.IsHost() {
|
|
|
|
return "host"
|
|
|
|
} else if n.IsContainer() {
|
|
|
|
return "container"
|
|
|
|
} else if n.IsNone() {
|
|
|
|
return "none"
|
|
|
|
} else if n.IsDefault() {
|
|
|
|
return "default"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// IsBridge indicates whether container uses the bridge network stack
|
2015-06-23 13:13:42 -04:00
|
|
|
func (n NetworkMode) IsBridge() bool {
|
|
|
|
return n == "bridge"
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// IsHost indicates whether container uses the host network stack.
|
2015-06-23 13:13:42 -04:00
|
|
|
func (n NetworkMode) IsHost() bool {
|
|
|
|
return n == "host"
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// IsContainer indicates whether container uses a container network stack.
|
2015-06-23 13:13:42 -04:00
|
|
|
func (n NetworkMode) IsContainer() bool {
|
|
|
|
parts := strings.SplitN(string(n), ":", 2)
|
|
|
|
return len(parts) > 1 && parts[0] == "container"
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// IsNone indicates whether container isn't using a network stack.
|
2015-06-23 13:13:42 -04:00
|
|
|
func (n NetworkMode) IsNone() bool {
|
|
|
|
return n == "none"
|
|
|
|
}
|
2015-07-09 18:12:36 -04:00
|
|
|
|
|
|
|
// MergeConfigs merges the specified container Config and HostConfig.
|
|
|
|
// It creates a ContainerConfigWrapper.
|
|
|
|
func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper {
|
|
|
|
return &ContainerConfigWrapper{
|
|
|
|
config,
|
|
|
|
hostConfig,
|
|
|
|
"", nil,
|
|
|
|
}
|
|
|
|
}
|