2015-05-04 12:44:37 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package windows
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-05-27 16:15:14 -04:00
|
|
|
"strings"
|
|
|
|
"sync"
|
2015-05-04 12:44:37 -04:00
|
|
|
|
2015-05-27 16:15:14 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-05-04 12:44:37 -04:00
|
|
|
"github.com/docker/docker/daemon/execdriver"
|
2015-11-09 13:32:46 -05:00
|
|
|
"github.com/docker/docker/dockerversion"
|
2015-05-27 16:15:14 -04:00
|
|
|
"github.com/docker/docker/pkg/parsers"
|
2016-01-04 19:05:26 -05:00
|
|
|
"github.com/docker/engine-api/types/container"
|
2015-05-04 12:44:37 -04:00
|
|
|
)
|
|
|
|
|
2015-05-27 16:15:14 -04:00
|
|
|
// This is a daemon development variable only and should not be
|
|
|
|
// used for running production containers on Windows.
|
|
|
|
var dummyMode bool
|
|
|
|
|
|
|
|
// This allows the daemon to terminate containers rather than shutdown
|
2015-10-12 19:34:03 -04:00
|
|
|
// This allows the daemon to force kill (HCS terminate) rather than shutdown
|
|
|
|
var forceKill bool
|
2015-05-27 16:15:14 -04:00
|
|
|
|
2015-12-18 13:36:17 -05:00
|
|
|
// DefaultIsolation allows users to specify a default isolation mode for
|
2015-10-31 22:16:58 -04:00
|
|
|
// when running a container on Windows. For example docker daemon -D
|
|
|
|
// --exec-opt isolation=hyperv will cause Windows to always run containers
|
|
|
|
// as Hyper-V containers unless otherwise specified.
|
2015-12-18 13:36:17 -05:00
|
|
|
var DefaultIsolation container.IsolationLevel = "process"
|
2015-10-31 22:16:58 -04:00
|
|
|
|
2015-08-02 21:54:02 -04:00
|
|
|
// Define name and version for windows
|
2015-05-27 16:15:14 -04:00
|
|
|
var (
|
|
|
|
DriverName = "Windows 1854"
|
2015-11-09 13:32:46 -05:00
|
|
|
Version = dockerversion.Version + " " + dockerversion.GitCommit
|
2015-05-04 12:44:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type activeContainer struct {
|
|
|
|
command *execdriver.Command
|
|
|
|
}
|
|
|
|
|
2015-08-02 21:54:02 -04:00
|
|
|
// Driver contains all information for windows driver,
|
|
|
|
// it implements execdriver.Driver
|
|
|
|
type Driver struct {
|
2015-05-27 16:15:14 -04:00
|
|
|
root string
|
|
|
|
activeContainers map[string]*activeContainer
|
|
|
|
sync.Mutex
|
2015-05-04 12:44:37 -04:00
|
|
|
}
|
|
|
|
|
2015-08-02 21:54:02 -04:00
|
|
|
// Name implements the exec driver Driver interface.
|
|
|
|
func (d *Driver) Name() string {
|
2015-12-18 13:36:17 -05:00
|
|
|
return fmt.Sprintf("\n Name: %s\n Build: %s \n Default Isolation: %s", DriverName, Version, DefaultIsolation)
|
2015-05-27 16:15:14 -04:00
|
|
|
}
|
|
|
|
|
2015-08-02 21:54:02 -04:00
|
|
|
// NewDriver returns a new windows driver, called from NewDriver of execdriver.
|
2015-11-30 04:04:13 -05:00
|
|
|
func NewDriver(root string, options []string) (*Driver, error) {
|
2015-05-27 16:15:14 -04:00
|
|
|
|
|
|
|
for _, option := range options {
|
|
|
|
key, val, err := parsers.ParseKeyValueOpt(option)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
key = strings.ToLower(key)
|
|
|
|
switch key {
|
|
|
|
|
|
|
|
case "dummy":
|
|
|
|
switch val {
|
|
|
|
case "1":
|
|
|
|
dummyMode = true
|
|
|
|
logrus.Warn("Using dummy mode in Windows exec driver. This is for development use only!")
|
|
|
|
}
|
|
|
|
|
2015-10-12 19:34:03 -04:00
|
|
|
case "forcekill":
|
2015-05-27 16:15:14 -04:00
|
|
|
switch val {
|
|
|
|
case "1":
|
2015-10-12 19:34:03 -04:00
|
|
|
forceKill = true
|
|
|
|
logrus.Warn("Using force kill mode in Windows exec driver. This is for testing purposes only.")
|
2015-05-27 16:15:14 -04:00
|
|
|
}
|
|
|
|
|
2015-10-31 22:16:58 -04:00
|
|
|
case "isolation":
|
2015-12-18 13:36:17 -05:00
|
|
|
if !container.IsolationLevel(val).IsValid() {
|
2015-10-31 22:16:58 -04:00
|
|
|
return nil, fmt.Errorf("Unrecognised exec driver option 'isolation':'%s'", val)
|
|
|
|
}
|
2015-12-18 13:36:17 -05:00
|
|
|
if container.IsolationLevel(val).IsHyperV() {
|
|
|
|
DefaultIsolation = "hyperv"
|
2015-10-31 22:16:58 -04:00
|
|
|
}
|
|
|
|
logrus.Infof("Windows default isolation level: '%s'", val)
|
2015-05-27 16:15:14 -04:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("Unrecognised exec driver option %s\n", key)
|
|
|
|
}
|
|
|
|
}
|
2015-05-04 12:44:37 -04:00
|
|
|
|
2015-08-02 21:54:02 -04:00
|
|
|
return &Driver{
|
2015-05-27 16:15:14 -04:00
|
|
|
root: root,
|
|
|
|
activeContainers: make(map[string]*activeContainer),
|
2015-05-04 12:44:37 -04:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2015-05-27 16:15:14 -04:00
|
|
|
// setupEnvironmentVariables convert a string array of environment variables
|
|
|
|
// into a map as required by the HCS. Source array is in format [v1=k1] [v2=k2] etc.
|
|
|
|
func setupEnvironmentVariables(a []string) map[string]string {
|
|
|
|
r := make(map[string]string)
|
|
|
|
for _, s := range a {
|
|
|
|
arr := strings.Split(s, "=")
|
|
|
|
if len(arr) == 2 {
|
|
|
|
r[arr[0]] = arr[1]
|
|
|
|
}
|
2015-05-04 12:44:37 -04:00
|
|
|
}
|
2015-05-27 16:15:14 -04:00
|
|
|
return r
|
2015-05-04 12:44:37 -04:00
|
|
|
}
|