2015-06-23 13:13:42 -04:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-07-09 18:12:36 -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), ":")
|
2015-06-23 13:13:42 -04:00
|
|
|
switch mode := parts[0]; mode {
|
2015-07-08 16:30:03 -04:00
|
|
|
case "default", "none":
|
2015-06-23 13:13:42 -04:00
|
|
|
default:
|
2015-07-09 18:12:36 -04:00
|
|
|
return fmt.Errorf("invalid --net: %s", hc.NetworkMode)
|
2015-06-23 13:13:42 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2015-09-18 21:21:57 -04:00
|
|
|
|
|
|
|
// ValidateIsolationLevel performs platform specific validation of the
|
|
|
|
// isolation level in the hostconfig structure. Windows supports 'default' (or
|
|
|
|
// blank), and 'hyperv'. These refer to Windows Server Containers and
|
|
|
|
// Hyper-V Containers respectively.
|
|
|
|
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() {
|
|
|
|
return fmt.Errorf("invalid --isolation: %q. Windows supports 'default' (Windows Server Container) or 'hyperv' (Hyper-V Container)", hc.Isolation)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|