github.com/endocode/docker@v1.4.2-0.20160113120958-46eb4700391e/daemon/execdriver/windows/windows.go (about) 1 // +build windows 2 3 package windows 4 5 import ( 6 "fmt" 7 "strings" 8 "sync" 9 10 "github.com/Sirupsen/logrus" 11 "github.com/docker/docker/daemon/execdriver" 12 "github.com/docker/docker/dockerversion" 13 "github.com/docker/docker/pkg/parsers" 14 "github.com/docker/engine-api/types/container" 15 ) 16 17 // This is a daemon development variable only and should not be 18 // used for running production containers on Windows. 19 var dummyMode bool 20 21 // This allows the daemon to terminate containers rather than shutdown 22 // This allows the daemon to force kill (HCS terminate) rather than shutdown 23 var forceKill bool 24 25 // DefaultIsolation allows users to specify a default isolation mode for 26 // when running a container on Windows. For example docker daemon -D 27 // --exec-opt isolation=hyperv will cause Windows to always run containers 28 // as Hyper-V containers unless otherwise specified. 29 var DefaultIsolation container.IsolationLevel = "process" 30 31 // Define name and version for windows 32 var ( 33 DriverName = "Windows 1854" 34 Version = dockerversion.Version + " " + dockerversion.GitCommit 35 ) 36 37 type activeContainer struct { 38 command *execdriver.Command 39 } 40 41 // Driver contains all information for windows driver, 42 // it implements execdriver.Driver 43 type Driver struct { 44 root string 45 activeContainers map[string]*activeContainer 46 sync.Mutex 47 } 48 49 // Name implements the exec driver Driver interface. 50 func (d *Driver) Name() string { 51 return fmt.Sprintf("\n Name: %s\n Build: %s \n Default Isolation: %s", DriverName, Version, DefaultIsolation) 52 } 53 54 // NewDriver returns a new windows driver, called from NewDriver of execdriver. 55 func NewDriver(root string, options []string) (*Driver, error) { 56 57 for _, option := range options { 58 key, val, err := parsers.ParseKeyValueOpt(option) 59 if err != nil { 60 return nil, err 61 } 62 key = strings.ToLower(key) 63 switch key { 64 65 case "dummy": 66 switch val { 67 case "1": 68 dummyMode = true 69 logrus.Warn("Using dummy mode in Windows exec driver. This is for development use only!") 70 } 71 72 case "forcekill": 73 switch val { 74 case "1": 75 forceKill = true 76 logrus.Warn("Using force kill mode in Windows exec driver. This is for testing purposes only.") 77 } 78 79 case "isolation": 80 if !container.IsolationLevel(val).IsValid() { 81 return nil, fmt.Errorf("Unrecognised exec driver option 'isolation':'%s'", val) 82 } 83 if container.IsolationLevel(val).IsHyperV() { 84 DefaultIsolation = "hyperv" 85 } 86 logrus.Infof("Windows default isolation level: '%s'", val) 87 default: 88 return nil, fmt.Errorf("Unrecognised exec driver option %s\n", key) 89 } 90 } 91 92 return &Driver{ 93 root: root, 94 activeContainers: make(map[string]*activeContainer), 95 }, nil 96 } 97 98 // setupEnvironmentVariables convert a string array of environment variables 99 // into a map as required by the HCS. Source array is in format [v1=k1] [v2=k2] etc. 100 func setupEnvironmentVariables(a []string) map[string]string { 101 r := make(map[string]string) 102 for _, s := range a { 103 arr := strings.Split(s, "=") 104 if len(arr) == 2 { 105 r[arr[0]] = arr[1] 106 } 107 } 108 return r 109 }