2015-06-23 13:13:42 -04:00
|
|
|
package runconfig
|
|
|
|
|
2015-10-31 21:49:14 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2015-10-31 22:16:58 -04:00
|
|
|
|
2016-01-04 19:05:26 -05:00
|
|
|
"github.com/docker/engine-api/types/container"
|
2015-12-18 13:36:17 -05:00
|
|
|
)
|
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-12-18 13:36:17 -05:00
|
|
|
func DefaultDaemonNetworkMode() container.NetworkMode {
|
2016-03-09 23:33:21 -05:00
|
|
|
return container.NetworkMode("nat")
|
2015-07-09 18:12:36 -04:00
|
|
|
}
|
2015-10-25 19:09:54 -04:00
|
|
|
|
|
|
|
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
|
|
|
|
func IsPreDefinedNetwork(network string) bool {
|
2016-03-09 23:33:21 -05:00
|
|
|
return !container.NetworkMode(network).IsUserDefined()
|
2015-10-25 19:09:54 -04:00
|
|
|
}
|
2015-10-31 21:49:14 -04:00
|
|
|
|
|
|
|
// ValidateNetMode ensures that the various combinations of requested
|
|
|
|
// network settings are valid.
|
2015-12-18 13:36:17 -05:00
|
|
|
func ValidateNetMode(c *container.Config, hc *container.HostConfig) error {
|
2015-10-31 21:49:14 -04:00
|
|
|
if hc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
parts := strings.Split(string(hc.NetworkMode), ":")
|
2016-03-09 23:33:21 -05:00
|
|
|
if len(parts) > 1 {
|
2015-10-31 21:49:14 -04:00
|
|
|
return fmt.Errorf("invalid --net: %s", hc.NetworkMode)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:07:00 -05:00
|
|
|
// ValidateIsolation performs platform specific validation of the
|
|
|
|
// isolation in the hostconfig structure. Windows supports 'default' (or
|
2015-10-31 22:16:58 -04:00
|
|
|
// blank), 'process', or 'hyperv'.
|
2016-02-03 15:07:00 -05:00
|
|
|
func ValidateIsolation(hc *container.HostConfig) error {
|
2015-10-31 21:49:14 -04:00
|
|
|
// 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
|
|
|
|
}
|
2016-02-24 20:51:46 -05:00
|
|
|
|
|
|
|
// ValidateQoS performs platform specific validation of the Qos settings
|
|
|
|
// a disk can be limited by either Bps or IOps, but not both.
|
|
|
|
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.IOMaximumIOps != 0 && hc.IOMaximumBandwidth != 0 {
|
|
|
|
return fmt.Errorf("invalid QoS settings: maximum bandwidth and maximum iops cannot both be set")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|