github.com/gondor/docker@v1.9.0-rc1/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/autogen/dockerversion"
    12  	"github.com/docker/docker/daemon/execdriver"
    13  	"github.com/docker/docker/pkg/parsers"
    14  )
    15  
    16  // This is a daemon development variable only and should not be
    17  // used for running production containers on Windows.
    18  var dummyMode bool
    19  
    20  // This allows the daemon to terminate containers rather than shutdown
    21  var terminateMode bool
    22  
    23  // Define name and version for windows
    24  var (
    25  	DriverName = "Windows 1854"
    26  	Version    = dockerversion.VERSION + " " + dockerversion.GITCOMMIT
    27  )
    28  
    29  type activeContainer struct {
    30  	command *execdriver.Command
    31  }
    32  
    33  // Driver contains all information for windows driver,
    34  // it implements execdriver.Driver
    35  type Driver struct {
    36  	root             string
    37  	initPath         string
    38  	activeContainers map[string]*activeContainer
    39  	sync.Mutex
    40  }
    41  
    42  // Name implements the exec driver Driver interface.
    43  func (d *Driver) Name() string {
    44  	return fmt.Sprintf("%s %s", DriverName, Version)
    45  }
    46  
    47  // NewDriver returns a new windows driver, called from NewDriver of execdriver.
    48  func NewDriver(root, initPath string, options []string) (*Driver, error) {
    49  
    50  	for _, option := range options {
    51  		key, val, err := parsers.ParseKeyValueOpt(option)
    52  		if err != nil {
    53  			return nil, err
    54  		}
    55  		key = strings.ToLower(key)
    56  		switch key {
    57  
    58  		case "dummy":
    59  			switch val {
    60  			case "1":
    61  				dummyMode = true
    62  				logrus.Warn("Using dummy mode in Windows exec driver. This is for development use only!")
    63  			}
    64  
    65  		case "terminate":
    66  			switch val {
    67  			case "1":
    68  				terminateMode = true
    69  				logrus.Warn("Using terminate mode in Windows exec driver. This is for testing purposes only.")
    70  			}
    71  
    72  		default:
    73  			return nil, fmt.Errorf("Unrecognised exec driver option %s\n", key)
    74  		}
    75  	}
    76  
    77  	return &Driver{
    78  		root:             root,
    79  		initPath:         initPath,
    80  		activeContainers: make(map[string]*activeContainer),
    81  	}, nil
    82  }
    83  
    84  // setupEnvironmentVariables convert a string array of environment variables
    85  // into a map as required by the HCS. Source array is in format [v1=k1] [v2=k2] etc.
    86  func setupEnvironmentVariables(a []string) map[string]string {
    87  	r := make(map[string]string)
    88  	for _, s := range a {
    89  		arr := strings.Split(s, "=")
    90  		if len(arr) == 2 {
    91  			r[arr[0]] = arr[1]
    92  		}
    93  	}
    94  	return r
    95  }