86d8758e |
// +build !windows,!solaris |
c5e6a4b3 |
package runconfig
import ( |
ee6c3580 |
"fmt"
"runtime" |
c5e6a4b3 |
"strings"
|
907407d0 |
"github.com/docker/engine-api/types/container" |
7ac4232e |
) |
c5e6a4b3 |
|
5170a2c0 |
// DefaultDaemonNetworkMode returns the default network stack the daemon should
// use. |
7ac4232e |
func DefaultDaemonNetworkMode() container.NetworkMode {
return container.NetworkMode("bridge") |
2ab94e11 |
}
|
ead62b59 |
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
func IsPreDefinedNetwork(network string) bool { |
7ac4232e |
n := container.NetworkMode(network) |
534a90a9 |
return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault() || network == "ingress" |
ead62b59 |
}
|
ee6c3580 |
// ValidateNetMode ensures that the various combinations of requested
// network settings are valid. |
7ac4232e |
func ValidateNetMode(c *container.Config, hc *container.HostConfig) error { |
ee6c3580 |
// 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), ":")
if parts[0] == "container" {
if len(parts) < 2 || parts[1] == "" {
return fmt.Errorf("--net: invalid net mode: invalid container format container:<name|id>")
}
}
|
3f445e63 |
if hc.NetworkMode.IsContainer() && c.Hostname != "" { |
ee6c3580 |
return ErrConflictNetworkHostname
}
|
3f445e63 |
if hc.UTSMode.IsHost() && c.Hostname != "" {
return ErrConflictUTSHostname
}
|
ee6c3580 |
if hc.NetworkMode.IsHost() && len(hc.Links) > 0 {
return ErrConflictHostNetworkAndLinks
}
if hc.NetworkMode.IsContainer() && len(hc.Links) > 0 {
return ErrConflictContainerNetworkAndLinks
}
|
23821fe5 |
if hc.NetworkMode.IsContainer() && len(hc.DNS) > 0 { |
ee6c3580 |
return ErrConflictNetworkAndDNS
}
|
90bd41a7 |
if hc.NetworkMode.IsContainer() && len(hc.ExtraHosts) > 0 { |
ee6c3580 |
return ErrConflictNetworkHosts
}
if (hc.NetworkMode.IsContainer() || hc.NetworkMode.IsHost()) && c.MacAddress != "" {
return ErrConflictContainerNetworkAndMac
}
if hc.NetworkMode.IsContainer() && (len(hc.PortBindings) > 0 || hc.PublishAllPorts == true) {
return ErrConflictNetworkPublishPorts
}
if hc.NetworkMode.IsContainer() && len(c.ExposedPorts) > 0 {
return ErrConflictNetworkExposePorts
}
return nil
}
|
d4b07324 |
// ValidateIsolation performs platform specific validation of
// isolation in the hostconfig structure. Linux only supports "default" |
ee6c3580 |
// which is LXC container isolation |
d4b07324 |
func ValidateIsolation(hc *container.HostConfig) error { |
ee6c3580 |
// 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() {
return fmt.Errorf("invalid --isolation: %q - %s only supports 'default'", hc.Isolation, runtime.GOOS)
}
return nil
} |
8df20663 |
// ValidateQoS performs platform specific validation of the QoS settings
func ValidateQoS(hc *container.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.IOMaximumBandwidth != 0 { |
ea3a7899 |
return fmt.Errorf("invalid QoS settings: %s does not support --io-maxbandwidth", runtime.GOOS) |
8df20663 |
}
if hc.IOMaximumIOps != 0 { |
ea3a7899 |
return fmt.Errorf("invalid QoS settings: %s does not support --io-maxiops", runtime.GOOS) |
8df20663 |
}
return nil
} |