mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
15e35c4470
Signed-off-by: John Howard <jhoward@microsoft.com>
96 lines
2.4 KiB
Go
96 lines
2.4 KiB
Go
// +build !windows
|
|
|
|
package runconfig
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// IsValid indicates is an isolation level is valid
|
|
func (i IsolationLevel) IsValid() bool {
|
|
return i.IsDefault()
|
|
}
|
|
|
|
// IsPrivate indicates whether container uses it's private network stack.
|
|
func (n NetworkMode) IsPrivate() bool {
|
|
return !(n.IsHost() || n.IsContainer())
|
|
}
|
|
|
|
// IsDefault indicates whether container uses the default network stack.
|
|
func (n NetworkMode) IsDefault() bool {
|
|
return n == "default"
|
|
}
|
|
|
|
// DefaultDaemonNetworkMode returns the default network stack the daemon should
|
|
// use.
|
|
func DefaultDaemonNetworkMode() NetworkMode {
|
|
return NetworkMode("bridge")
|
|
}
|
|
|
|
// NetworkName returns the name of the network stack.
|
|
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"
|
|
} else if n.IsUserDefined() {
|
|
return n.UserDefined()
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// IsBridge indicates whether container uses the bridge network stack
|
|
func (n NetworkMode) IsBridge() bool {
|
|
return n == "bridge"
|
|
}
|
|
|
|
// IsHost indicates whether container uses the host network stack.
|
|
func (n NetworkMode) IsHost() bool {
|
|
return n == "host"
|
|
}
|
|
|
|
// IsContainer indicates whether container uses a container network stack.
|
|
func (n NetworkMode) IsContainer() bool {
|
|
parts := strings.SplitN(string(n), ":", 2)
|
|
return len(parts) > 1 && parts[0] == "container"
|
|
}
|
|
|
|
// IsNone indicates whether container isn't using a network stack.
|
|
func (n NetworkMode) IsNone() bool {
|
|
return n == "none"
|
|
}
|
|
|
|
// IsUserDefined indicates user-created network
|
|
func (n NetworkMode) IsUserDefined() bool {
|
|
return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer()
|
|
}
|
|
|
|
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
|
|
func IsPreDefinedNetwork(network string) bool {
|
|
n := NetworkMode(network)
|
|
return n.IsBridge() || n.IsHost() || n.IsNone()
|
|
}
|
|
|
|
//UserDefined indicates user-created network
|
|
func (n NetworkMode) UserDefined() string {
|
|
if n.IsUserDefined() {
|
|
return string(n)
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// MergeConfigs merges the specified container Config and HostConfig.
|
|
// It creates a ContainerConfigWrapper.
|
|
func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper {
|
|
return &ContainerConfigWrapper{
|
|
config,
|
|
hostConfig,
|
|
"", nil,
|
|
}
|
|
}
|