interface.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package hcsshim
  2. import (
  3. "encoding/json"
  4. "io"
  5. "time"
  6. )
  7. // ProcessConfig is used as both the input of Container.CreateProcess
  8. // and to convert the parameters to JSON for passing onto the HCS
  9. type ProcessConfig struct {
  10. ApplicationName string `json:",omitempty"`
  11. CommandLine string `json:",omitempty"`
  12. CommandArgs []string `json:",omitempty"` // Used by Linux Containers on Windows
  13. User string `json:",omitempty"`
  14. WorkingDirectory string `json:",omitempty"`
  15. Environment map[string]string `json:",omitempty"`
  16. EmulateConsole bool `json:",omitempty"`
  17. CreateStdInPipe bool `json:",omitempty"`
  18. CreateStdOutPipe bool `json:",omitempty"`
  19. CreateStdErrPipe bool `json:",omitempty"`
  20. ConsoleSize [2]uint `json:",omitempty"`
  21. CreateInUtilityVm bool `json:",omitempty"` // Used by Linux Containers on Windows
  22. OCISpecification *json.RawMessage `json:",omitempty"` // Used by Linux Containers on Windows
  23. }
  24. type Layer struct {
  25. ID string
  26. Path string
  27. }
  28. type MappedDir struct {
  29. HostPath string
  30. ContainerPath string
  31. ReadOnly bool
  32. BandwidthMaximum uint64
  33. IOPSMaximum uint64
  34. CreateInUtilityVM bool
  35. }
  36. type MappedPipe struct {
  37. HostPath string
  38. ContainerPipeName string
  39. }
  40. type HvRuntime struct {
  41. ImagePath string `json:",omitempty"`
  42. SkipTemplate bool `json:",omitempty"`
  43. LinuxInitrdFile string `json:",omitempty"` // File under ImagePath on host containing an initrd image for starting a Linux utility VM
  44. LinuxKernelFile string `json:",omitempty"` // File under ImagePath on host containing a kernel for starting a Linux utility VM
  45. LinuxBootParameters string `json:",omitempty"` // Additional boot parameters for starting a Linux Utility VM in initrd mode
  46. BootSource string `json:",omitempty"` // "Vhd" for Linux Utility VM booting from VHD
  47. WritableBootSource bool `json:",omitempty"` // Linux Utility VM booting from VHD
  48. }
  49. type MappedVirtualDisk struct {
  50. HostPath string `json:",omitempty"` // Path to VHD on the host
  51. ContainerPath string // Platform-specific mount point path in the container
  52. CreateInUtilityVM bool `json:",omitempty"`
  53. ReadOnly bool `json:",omitempty"`
  54. Cache string `json:",omitempty"` // "" (Unspecified); "Disabled"; "Enabled"; "Private"; "PrivateAllowSharing"
  55. AttachOnly bool `json:",omitempty:`
  56. }
  57. // ContainerConfig is used as both the input of CreateContainer
  58. // and to convert the parameters to JSON for passing onto the HCS
  59. type ContainerConfig struct {
  60. SystemType string // HCS requires this to be hard-coded to "Container"
  61. Name string // Name of the container. We use the docker ID.
  62. Owner string `json:",omitempty"` // The management platform that created this container
  63. VolumePath string `json:",omitempty"` // Windows volume path for scratch space. Used by Windows Server Containers only. Format \\?\\Volume{GUID}
  64. IgnoreFlushesDuringBoot bool `json:",omitempty"` // Optimization hint for container startup in Windows
  65. LayerFolderPath string `json:",omitempty"` // Where the layer folders are located. Used by Windows Server Containers only. Format %root%\windowsfilter\containerID
  66. Layers []Layer // List of storage layers. Required for Windows Server and Hyper-V Containers. Format ID=GUID;Path=%root%\windowsfilter\layerID
  67. Credentials string `json:",omitempty"` // Credentials information
  68. ProcessorCount uint32 `json:",omitempty"` // Number of processors to assign to the container.
  69. ProcessorWeight uint64 `json:",omitempty"` // CPU shares (relative weight to other containers with cpu shares). Range is from 1 to 10000. A value of 0 results in default shares.
  70. ProcessorMaximum int64 `json:",omitempty"` // Specifies the portion of processor cycles that this container can use as a percentage times 100. Range is from 1 to 10000. A value of 0 results in no limit.
  71. StorageIOPSMaximum uint64 `json:",omitempty"` // Maximum Storage IOPS
  72. StorageBandwidthMaximum uint64 `json:",omitempty"` // Maximum Storage Bandwidth in bytes per second
  73. StorageSandboxSize uint64 `json:",omitempty"` // Size in bytes that the container system drive should be expanded to if smaller
  74. MemoryMaximumInMB int64 `json:",omitempty"` // Maximum memory available to the container in Megabytes
  75. HostName string `json:",omitempty"` // Hostname
  76. MappedDirectories []MappedDir `json:",omitempty"` // List of mapped directories (volumes/mounts)
  77. MappedPipes []MappedPipe `json:",omitempty"` // List of mapped Windows named pipes
  78. HvPartition bool // True if it a Hyper-V Container
  79. NetworkSharedContainerName string `json:",omitempty"` // Name (ID) of the container that we will share the network stack with.
  80. EndpointList []string `json:",omitempty"` // List of networking endpoints to be attached to container
  81. HvRuntime *HvRuntime `json:",omitempty"` // Hyper-V container settings. Used by Hyper-V containers only. Format ImagePath=%root%\BaseLayerID\UtilityVM
  82. Servicing bool `json:",omitempty"` // True if this container is for servicing
  83. AllowUnqualifiedDNSQuery bool `json:",omitempty"` // True to allow unqualified DNS name resolution
  84. DNSSearchList string `json:",omitempty"` // Comma seperated list of DNS suffixes to use for name resolution
  85. ContainerType string `json:",omitempty"` // "Linux" for Linux containers on Windows. Omitted otherwise.
  86. TerminateOnLastHandleClosed bool `json:",omitempty"` // Should HCS terminate the container once all handles have been closed
  87. MappedVirtualDisks []MappedVirtualDisk `json:",omitempty"` // Array of virtual disks to mount at start
  88. }
  89. type ComputeSystemQuery struct {
  90. IDs []string `json:"Ids,omitempty"`
  91. Types []string `json:",omitempty"`
  92. Names []string `json:",omitempty"`
  93. Owners []string `json:",omitempty"`
  94. }
  95. // Container represents a created (but not necessarily running) container.
  96. type Container interface {
  97. // Start synchronously starts the container.
  98. Start() error
  99. // Shutdown requests a container shutdown, but it may not actually be shutdown until Wait() succeeds.
  100. Shutdown() error
  101. // Terminate requests a container terminate, but it may not actually be terminated until Wait() succeeds.
  102. Terminate() error
  103. // Waits synchronously waits for the container to shutdown or terminate.
  104. Wait() error
  105. // WaitTimeout synchronously waits for the container to terminate or the duration to elapse. It
  106. // returns false if timeout occurs.
  107. WaitTimeout(time.Duration) error
  108. // Pause pauses the execution of a container.
  109. Pause() error
  110. // Resume resumes the execution of a container.
  111. Resume() error
  112. // HasPendingUpdates returns true if the container has updates pending to install.
  113. HasPendingUpdates() (bool, error)
  114. // Statistics returns statistics for a container.
  115. Statistics() (Statistics, error)
  116. // ProcessList returns details for the processes in a container.
  117. ProcessList() ([]ProcessListItem, error)
  118. // MappedVirtualDisks returns virtual disks mapped to a utility VM, indexed by controller
  119. MappedVirtualDisks() (map[int]MappedVirtualDiskController, error)
  120. // CreateProcess launches a new process within the container.
  121. CreateProcess(c *ProcessConfig) (Process, error)
  122. // OpenProcess gets an interface to an existing process within the container.
  123. OpenProcess(pid int) (Process, error)
  124. // Close cleans up any state associated with the container but does not terminate or wait for it.
  125. Close() error
  126. // Modify the System
  127. Modify(config *ResourceModificationRequestResponse) error
  128. }
  129. // Process represents a running or exited process.
  130. type Process interface {
  131. // Pid returns the process ID of the process within the container.
  132. Pid() int
  133. // Kill signals the process to terminate but does not wait for it to finish terminating.
  134. Kill() error
  135. // Wait waits for the process to exit.
  136. Wait() error
  137. // WaitTimeout waits for the process to exit or the duration to elapse. It returns
  138. // false if timeout occurs.
  139. WaitTimeout(time.Duration) error
  140. // ExitCode returns the exit code of the process. The process must have
  141. // already terminated.
  142. ExitCode() (int, error)
  143. // ResizeConsole resizes the console of the process.
  144. ResizeConsole(width, height uint16) error
  145. // Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
  146. // these pipes does not close the underlying pipes; it should be possible to
  147. // call this multiple times to get multiple interfaces.
  148. Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error)
  149. // CloseStdin closes the write side of the stdin pipe so that the process is
  150. // notified on the read side that there is no more data in stdin.
  151. CloseStdin() error
  152. // Close cleans up any state associated with the process but does not kill
  153. // or wait on it.
  154. Close() error
  155. }