2015-06-23 13:13:42 -04:00
|
|
|
package runconfig
|
|
|
|
|
2015-10-31 21:49:14 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
2015-09-18 21:21:57 -04:00
|
|
|
|
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-10-31 22:16:58 -04:00
|
|
|
// IsHyperV indicates the use of a Hyper-V partition for isolation
|
2015-09-18 21:21:57 -04:00
|
|
|
func (i IsolationLevel) IsHyperV() bool {
|
|
|
|
return strings.ToLower(string(i)) == "hyperv"
|
|
|
|
}
|
|
|
|
|
2015-10-31 22:16:58 -04:00
|
|
|
// IsProcess indicates the use of process isolation
|
|
|
|
func (i IsolationLevel) IsProcess() bool {
|
|
|
|
return strings.ToLower(string(i)) == "process"
|
|
|
|
}
|
|
|
|
|
2015-09-18 21:21:57 -04:00
|
|
|
// IsValid indicates is an isolation level is valid
|
|
|
|
func (i IsolationLevel) IsValid() bool {
|
2015-10-31 22:16:58 -04:00
|
|
|
return i.IsDefault() || i.IsHyperV() || i.IsProcess()
|
2015-09-18 21:21:57 -04:00
|
|
|
}
|
|
|
|
|
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("default")
|
|
|
|
}
|
|
|
|
|
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.IsDefault() {
|
|
|
|
return "default"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
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,
|
|
|
|
}
|
|
|
|
}
|
2015-10-25 19:09:54 -04:00
|
|
|
|
|
|
|
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
|
|
|
|
func IsPreDefinedNetwork(network string) bool {
|
|
|
|
return false
|
|
|
|
}
|
2015-10-31 21:49:14 -04:00
|
|
|
|
|
|
|
// ValidateNetMode ensures that the various combinations of requested
|
|
|
|
// network settings are valid.
|
|
|
|
func ValidateNetMode(c *Config, hc *HostConfig) error {
|
|
|
|
// We may not be passed a host config, such as in the case of docker commit
|
|
|
|
if hc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
parts := strings.Split(string(hc.NetworkMode), ":")
|
|
|
|
switch mode := parts[0]; mode {
|
|
|
|
case "default", "none":
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("invalid --net: %s", hc.NetworkMode)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateIsolationLevel performs platform specific validation of the
|
|
|
|
// isolation level in the hostconfig structure. Windows supports 'default' (or
|
2015-10-31 22:16:58 -04:00
|
|
|
// blank), 'process', or 'hyperv'.
|
2015-10-31 21:49:14 -04:00
|
|
|
func ValidateIsolationLevel(hc *HostConfig) error {
|
|
|
|
// We may not be passed a host config, such as in the case of docker commit
|
|
|
|
if hc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if !hc.Isolation.IsValid() {
|
2015-10-31 22:16:58 -04:00
|
|
|
return fmt.Errorf("invalid --isolation: %q. Windows supports 'default', 'process', or 'hyperv'", hc.Isolation)
|
2015-10-31 21:49:14 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|