2015-06-23 17:13:42 +00:00
|
|
|
package runconfig
|
|
|
|
|
2015-11-01 01:49:14 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2015-11-01 02:16:58 +00:00
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-06-07 19:05:43 +00:00
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
2015-12-18 18:36:17 +00:00
|
|
|
)
|
2015-09-19 01:21:57 +00:00
|
|
|
|
2015-07-25 09:11:45 +00:00
|
|
|
// DefaultDaemonNetworkMode returns the default network stack the daemon should
|
|
|
|
// use.
|
2015-12-18 18:36:17 +00:00
|
|
|
func DefaultDaemonNetworkMode() container.NetworkMode {
|
2016-03-10 04:33:21 +00:00
|
|
|
return container.NetworkMode("nat")
|
2015-07-09 22:12:36 +00:00
|
|
|
}
|
2015-10-25 23:09:54 +00:00
|
|
|
|
|
|
|
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
|
|
|
|
func IsPreDefinedNetwork(network string) bool {
|
2016-03-10 04:33:21 +00:00
|
|
|
return !container.NetworkMode(network).IsUserDefined()
|
2015-10-25 23:09:54 +00:00
|
|
|
}
|
2015-11-01 01:49:14 +00:00
|
|
|
|
|
|
|
// ValidateNetMode ensures that the various combinations of requested
|
|
|
|
// network settings are valid.
|
2015-12-18 18:36:17 +00:00
|
|
|
func ValidateNetMode(c *container.Config, hc *container.HostConfig) error {
|
2015-11-01 01:49:14 +00:00
|
|
|
if hc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
parts := strings.Split(string(hc.NetworkMode), ":")
|
2016-03-10 04:33:21 +00:00
|
|
|
if len(parts) > 1 {
|
2015-11-01 01:49:14 +00:00
|
|
|
return fmt.Errorf("invalid --net: %s", hc.NetworkMode)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-03 20:07:00 +00:00
|
|
|
// ValidateIsolation performs platform specific validation of the
|
|
|
|
// isolation in the hostconfig structure. Windows supports 'default' (or
|
2015-11-01 02:16:58 +00:00
|
|
|
// blank), 'process', or 'hyperv'.
|
2016-02-03 20:07:00 +00:00
|
|
|
func ValidateIsolation(hc *container.HostConfig) error {
|
2015-11-01 01:49:14 +00: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-11-01 02:16:58 +00:00
|
|
|
return fmt.Errorf("invalid --isolation: %q. Windows supports 'default', 'process', or 'hyperv'", hc.Isolation)
|
2015-11-01 01:49:14 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-02-25 01:51:46 +00:00
|
|
|
|
|
|
|
// ValidateQoS performs platform specific validation of the Qos settings
|
|
|
|
func ValidateQoS(hc *container.HostConfig) error {
|
|
|
|
return nil
|
|
|
|
}
|
2016-06-07 19:05:43 +00:00
|
|
|
|
|
|
|
// ValidateResources performs platform specific validation of the resource settings
|
|
|
|
func ValidateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error {
|
|
|
|
// We may not be passed a host config, such as in the case of docker commit
|
|
|
|
if hc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if hc.Resources.CPURealtimePeriod != 0 {
|
|
|
|
return fmt.Errorf("invalid --cpu-rt-period: Windows does not support this feature")
|
|
|
|
}
|
|
|
|
if hc.Resources.CPURealtimeRuntime != 0 {
|
|
|
|
return fmt.Errorf("invalid --cpu-rt-runtime: Windows does not support this feature")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|