mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			84 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package runconfig
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
	"strings"
 | 
						|
)
 | 
						|
 | 
						|
// IsDefault indicates whether container uses the default network stack.
 | 
						|
func (n NetworkMode) IsDefault() bool {
 | 
						|
	return n == "default"
 | 
						|
}
 | 
						|
 | 
						|
// IsHyperV indicates the use of a Hyper-V partition for isolation
 | 
						|
func (i IsolationLevel) IsHyperV() bool {
 | 
						|
	return strings.ToLower(string(i)) == "hyperv"
 | 
						|
}
 | 
						|
 | 
						|
// IsProcess indicates the use of process isolation
 | 
						|
func (i IsolationLevel) IsProcess() bool {
 | 
						|
	return strings.ToLower(string(i)) == "process"
 | 
						|
}
 | 
						|
 | 
						|
// IsValid indicates is an isolation level is valid
 | 
						|
func (i IsolationLevel) IsValid() bool {
 | 
						|
	return i.IsDefault() || i.IsHyperV() || i.IsProcess()
 | 
						|
}
 | 
						|
 | 
						|
// DefaultDaemonNetworkMode returns the default network stack the daemon should
 | 
						|
// use.
 | 
						|
func DefaultDaemonNetworkMode() NetworkMode {
 | 
						|
	return NetworkMode("default")
 | 
						|
}
 | 
						|
 | 
						|
// NetworkName returns the name of the network stack.
 | 
						|
func (n NetworkMode) NetworkName() string {
 | 
						|
	if n.IsDefault() {
 | 
						|
		return "default"
 | 
						|
	}
 | 
						|
	return ""
 | 
						|
}
 | 
						|
 | 
						|
// MergeConfigs merges the specified container Config and HostConfig.
 | 
						|
// It creates a ContainerConfigWrapper.
 | 
						|
func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper {
 | 
						|
	return &ContainerConfigWrapper{
 | 
						|
		config,
 | 
						|
		hostConfig,
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
 | 
						|
func IsPreDefinedNetwork(network string) bool {
 | 
						|
	return false
 | 
						|
}
 | 
						|
 | 
						|
// 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
 | 
						|
// blank), 'process', or 'hyperv'.
 | 
						|
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', 'process', or 'hyperv'", hc.Isolation)
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 |