interface.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package hcsshim
  2. import (
  3. "io"
  4. "time"
  5. )
  6. // ProcessConfig is used as both the input of Container.CreateProcess
  7. // and to convert the parameters to JSON for passing onto the HCS
  8. type ProcessConfig struct {
  9. ApplicationName string
  10. CommandLine string
  11. User string
  12. WorkingDirectory string
  13. Environment map[string]string
  14. EmulateConsole bool
  15. CreateStdInPipe bool
  16. CreateStdOutPipe bool
  17. CreateStdErrPipe bool
  18. ConsoleSize [2]uint
  19. }
  20. type Layer struct {
  21. ID string
  22. Path string
  23. }
  24. type MappedDir struct {
  25. HostPath string
  26. ContainerPath string
  27. ReadOnly bool
  28. BandwidthMaximum uint64
  29. IOPSMaximum uint64
  30. }
  31. type HvRuntime struct {
  32. ImagePath string `json:",omitempty"`
  33. SkipTemplate bool `json:",omitempty"`
  34. }
  35. // ContainerConfig is used as both the input of CreateContainer
  36. // and to convert the parameters to JSON for passing onto the HCS
  37. type ContainerConfig struct {
  38. SystemType string // HCS requires this to be hard-coded to "Container"
  39. Name string // Name of the container. We use the docker ID.
  40. Owner string // The management platform that created this container
  41. IsDummy bool // Used for development purposes.
  42. VolumePath string `json:",omitempty"` // Windows volume path for scratch space. Used by Windows Server Containers only. Format \\?\\Volume{GUID}
  43. IgnoreFlushesDuringBoot bool // Optimization hint for container startup in Windows
  44. LayerFolderPath string `json:",omitempty"` // Where the layer folders are located. Used by Windows Server Containers only. Format %root%\windowsfilter\containerID
  45. Layers []Layer // List of storage layers. Required for Windows Server and Hyper-V Containers. Format ID=GUID;Path=%root%\windowsfilter\layerID
  46. Credentials string `json:",omitempty"` // Credentials information
  47. ProcessorCount uint32 `json:",omitempty"` // Number of processors to assign to the container.
  48. ProcessorWeight uint64 `json:",omitempty"` // CPU Shares 0..10000 on Windows; where 0 will be omitted and HCS will default.
  49. ProcessorMaximum int64 `json:",omitempty"` // CPU maximum usage percent 1..100
  50. StorageIOPSMaximum uint64 `json:",omitempty"` // Maximum Storage IOPS
  51. StorageBandwidthMaximum uint64 `json:",omitempty"` // Maximum Storage Bandwidth in bytes per second
  52. StorageSandboxSize uint64 `json:",omitempty"` // Size in bytes that the container system drive should be expanded to if smaller
  53. MemoryMaximumInMB int64 `json:",omitempty"` // Maximum memory available to the container in Megabytes
  54. HostName string // Hostname
  55. MappedDirectories []MappedDir // List of mapped directories (volumes/mounts)
  56. SandboxPath string `json:",omitempty"` // Location of unmounted sandbox. Used by Hyper-V containers only. Format %root%\windowsfilter
  57. HvPartition bool // True if it a Hyper-V Container
  58. EndpointList []string // List of networking endpoints to be attached to container
  59. NetworkSharedContainerName string `json:",omitempty"` // Name (ID) of the container that we will share the network stack with.
  60. HvRuntime *HvRuntime `json:",omitempty"` // Hyper-V container settings. Used by Hyper-V containers only. Format ImagePath=%root%\BaseLayerID\UtilityVM
  61. Servicing bool // True if this container is for servicing
  62. AllowUnqualifiedDNSQuery bool // True to allow unqualified DNS name resolution
  63. DNSSearchList string `json:",omitempty"` // Comma seperated list of DNS suffixes to use for name resolution
  64. }
  65. type ComputeSystemQuery struct {
  66. IDs []string `json:"Ids,omitempty"`
  67. Types []string `json:",omitempty"`
  68. Names []string `json:",omitempty"`
  69. Owners []string `json:",omitempty"`
  70. }
  71. // Container represents a created (but not necessarily running) container.
  72. type Container interface {
  73. // Start synchronously starts the container.
  74. Start() error
  75. // Shutdown requests a container shutdown, but it may not actually be shutdown until Wait() succeeds.
  76. Shutdown() error
  77. // Terminate requests a container terminate, but it may not actually be terminated until Wait() succeeds.
  78. Terminate() error
  79. // Waits synchronously waits for the container to shutdown or terminate.
  80. Wait() error
  81. // WaitTimeout synchronously waits for the container to terminate or the duration to elapse. It
  82. // returns false if timeout occurs.
  83. WaitTimeout(time.Duration) error
  84. // Pause pauses the execution of a container.
  85. Pause() error
  86. // Resume resumes the execution of a container.
  87. Resume() error
  88. // HasPendingUpdates returns true if the container has updates pending to install.
  89. HasPendingUpdates() (bool, error)
  90. // Statistics returns statistics for a container.
  91. Statistics() (Statistics, error)
  92. // ProcessList returns details for the processes in a container.
  93. ProcessList() ([]ProcessListItem, error)
  94. // CreateProcess launches a new process within the container.
  95. CreateProcess(c *ProcessConfig) (Process, error)
  96. // OpenProcess gets an interface to an existing process within the container.
  97. OpenProcess(pid int) (Process, error)
  98. // Close cleans up any state associated with the container but does not terminate or wait for it.
  99. Close() error
  100. // Modify the System
  101. Modify(config *ResourceModificationRequestResponse) error
  102. }
  103. // Process represents a running or exited process.
  104. type Process interface {
  105. // Pid returns the process ID of the process within the container.
  106. Pid() int
  107. // Kill signals the process to terminate but does not wait for it to finish terminating.
  108. Kill() error
  109. // Wait waits for the process to exit.
  110. Wait() error
  111. // WaitTimeout waits for the process to exit or the duration to elapse. It returns
  112. // false if timeout occurs.
  113. WaitTimeout(time.Duration) error
  114. // ExitCode returns the exit code of the process. The process must have
  115. // already terminated.
  116. ExitCode() (int, error)
  117. // ResizeConsole resizes the console of the process.
  118. ResizeConsole(width, height uint16) error
  119. // Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
  120. // these pipes does not close the underlying pipes; it should be possible to
  121. // call this multiple times to get multiple interfaces.
  122. Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error)
  123. // CloseStdin closes the write side of the stdin pipe so that the process is
  124. // notified on the read side that there is no more data in stdin.
  125. CloseStdin() error
  126. // Close cleans up any state associated with the process but does not kill
  127. // or wait on it.
  128. Close() error
  129. }