2015-06-23 20:13:42 +03:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-07-25 12:11:45 +03:00
|
|
|
// IsPrivate indicates whether container uses it's private network stack.
|
2015-06-23 20:13:42 +03:00
|
|
|
func (n NetworkMode) IsPrivate() bool {
|
|
|
|
return !(n.IsHost() || n.IsContainer())
|
|
|
|
}
|
|
|
|
|
2015-07-25 12:11:45 +03:00
|
|
|
// IsDefault indicates whether container uses the default network stack.
|
2015-06-23 20:13:42 +03:00
|
|
|
func (n NetworkMode) IsDefault() bool {
|
|
|
|
return n == "default"
|
|
|
|
}
|
|
|
|
|
2015-07-25 12:11:45 +03:00
|
|
|
// DefaultDaemonNetworkMode returns the default network stack the daemon should
|
|
|
|
// use.
|
2015-06-23 20:13:42 +03:00
|
|
|
func DefaultDaemonNetworkMode() NetworkMode {
|
|
|
|
return NetworkMode("bridge")
|
|
|
|
}
|
|
|
|
|
2015-07-25 12:11:45 +03:00
|
|
|
// NetworkName returns the name of the network stack.
|
2015-06-23 20:13:42 +03: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 12:11:45 +03:00
|
|
|
// IsBridge indicates whether container uses the bridge network stack
|
2015-06-23 20:13:42 +03:00
|
|
|
func (n NetworkMode) IsBridge() bool {
|
|
|
|
return n == "bridge"
|
|
|
|
}
|
|
|
|
|
2015-07-25 12:11:45 +03:00
|
|
|
// IsHost indicates whether container uses the host network stack.
|
2015-06-23 20:13:42 +03:00
|
|
|
func (n NetworkMode) IsHost() bool {
|
|
|
|
return n == "host"
|
|
|
|
}
|
|
|
|
|
2015-07-25 12:11:45 +03:00
|
|
|
// IsContainer indicates whether container uses a container network stack.
|
2015-06-23 20:13:42 +03:00
|
|
|
func (n NetworkMode) IsContainer() bool {
|
|
|
|
parts := strings.SplitN(string(n), ":", 2)
|
|
|
|
return len(parts) > 1 && parts[0] == "container"
|
|
|
|
}
|
|
|
|
|
2015-07-25 12:11:45 +03:00
|
|
|
// IsNone indicates whether container isn't using a network stack.
|
2015-06-23 20:13:42 +03:00
|
|
|
func (n NetworkMode) IsNone() bool {
|
|
|
|
return n == "none"
|
|
|
|
}
|