windows.go 2.3 KB

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